From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id JAA23465 for caml-red; Tue, 3 Oct 2000 09:33:16 +0200 (MET DST) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id IAA18201 for ; Tue, 3 Oct 2000 08:41:09 +0200 (MET DST) Received: from dopamine.iq.org (dopamine.iq.org [203.4.184.129]) by nez-perce.inria.fr (8.10.0/8.10.0) with ESMTP id e936f6T00576 for ; Tue, 3 Oct 2000 08:41:07 +0200 (MET DST) Received: by dopamine.iq.org (Postfix, from userid 110) id EEAB7FDB3; Tue, 3 Oct 2000 03:39:01 +1100 (EST) To: caml-list@inria.fr Subject: list of objects Cc: proff@iq.org From: Julian Assange Date: 03 Oct 2000 03:38:59 +1100 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: weis@pauillac.inria.fr I have a variety of signature schemes for text. I'd like to have a list of these schemes, so I can do such things as: List.map (fun x -> x#make text) schemes Neither classes or modules are first class objects. However, objects are. So, my first thought was to create something along the lines of let schemes = [new scheme_11; ...; new scheme_n] Since the objects are functional (at least so far) this seems like an acceptable approach. class virtual signature = object end class ['a] plain = object (self) inherit signature method make s = s method digest s = Digest.string (self#make s) method compare (a:'a) b = a = b end class ['a] simple = object inherit ['a] plain method make s = string_filter (alphabetize >> lower) s end let sig_list = [new plain; new simple] On compilation, this produces: The type of this expression, '_a Sigs.plain list, contains type variables that cannot be generalized However sending the exact same code to the top level, produces: module Sigs : sig val vanilla : 'a -> 'a val lower : char option -> char option val alphabetize : char option -> char option val string_filter : (char option -> char option) -> string -> string class virtual signature : object end class ['a] plain : object method compare : 'a -> 'a -> bool method digest : string -> Digest.t method make : string -> string end class ['a] simple : object method compare : 'a -> 'a -> bool method digest : string -> Digest.t method make : string -> string end end val sig_list : '_a Sigs.plain list = [; ] Works just fine! What gives?