From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id GAA15091; Mon, 28 May 2001 06:16:00 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id GAA15085 for ; Mon, 28 May 2001 06:15:59 +0200 (MET DST) Received: from shell5.ba.best.com (shell5.ba.best.com [206.184.139.136]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f4S4Fwj06310 for ; Mon, 28 May 2001 06:15:58 +0200 (MET DST) Received: from localhost (bpr@localhost) by shell5.ba.best.com (8.9.3/8.9.2/best.sh) with ESMTP id VAA27650; Sun, 27 May 2001 21:15:56 -0700 (PDT) Date: Sun, 27 May 2001 21:15:56 -0700 (PDT) From: Brian Rogoff To: Tom _ cc: caml-list@inria.fr Subject: Re: [Caml-list] classes vs modules In-Reply-To: <20010527235252.69384.qmail@web11906.mail.yahoo.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Sun, 27 May 2001, Tom _ wrote: > > You can do this now if you make a PolySet module by > > copying the > > "monomorphic" implementation from the stdlib, > > changing elt and t to > > 'a elt and 'a t and, using that instead of Set, > > something like: > > > > let f (cmp : 'a -> 'a -> bool) = > > let module SomeSet = > > PolySet.Make > > (struct type 'a t = 'a let compare = > > Pervasives.compare end) in > > () > > Thanks; that's very useful to know, and it seems > to be working. I think it might be useful to feature > the ability to have polymorphic types in modules > a little more prominently in the documentation. Yes, or you have to make a habit of reading lots of the posts from yesteryear in the mailing list archive. There is a lot of good information there, unfortunately it isn't so easy to find. > Maybe some of the standard modules could take > advantage of this more (it would require some > changes to their interfaces, I suppose). Yes, the interfaces would have to change. I think it is better that the interfaces don't have type variables; really the most compelling (IMO of course!) reason for making them polymorphic is to use the parameterization trick for recursive types, and I am hoping that a future OCaml (OCaml 4?) handles this nicely by stealing Moscow ML features or by adopting the mixin modules described briefly here by Tom Hirschowitz a few months ago. > The type signatures I get out of my module after > converting it are a little odd looking: > > type 'a t = 'a > type 'a tree = Empty | Node of ... > val insert : > ('a t t t -> 'a t t -> bool) -> > 'a t t t -> 'a t tree -> 'a tree > ... > > Is there any useful information in the different > number of t's? They should all be equivalent, right? Something looks wrong to me here. Could you post more of your code, or provide a pointer to the original SML code? I don't see why you have a 'a t t t. The OCaml code should look a lot like the SML code, and the signatures should only differ a little. > BTW, I opted for just passing the "lt" function > as explicit arguments to all the functions in the > module that need them. Why not just parameterize the module by the comparison function? > That seems like the most general approach, although it means some extra > arguments and it doesn't guarantee consistency, > as people might pass incompatible versions of "lt" > to different calls; Right, I think you should pull the comaprison out of the functions and parameterize the module for this reason. -- Brian ------------------- To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr