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 WAA12041; Sun, 27 May 2001 22:54:32 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 WAA12025 for ; Sun, 27 May 2001 22:54:31 +0200 (MET DST) Received: from shell5.ba.best.com (shell5.ba.best.com [206.184.139.136]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id f4RKsTH11865 for ; Sun, 27 May 2001 22:54:30 +0200 (MET DST) Received: from localhost (bpr@localhost) by shell5.ba.best.com (8.9.3/8.9.2/best.sh) with ESMTP id NAA09647; Sun, 27 May 2001 13:54:21 -0700 (PDT) Date: Sun, 27 May 2001 13:54:21 -0700 (PDT) From: Brian Rogoff To: Markus Mottl cc: Tom _ , caml-list@inria.fr Subject: Re: [Caml-list] classes vs modules In-Reply-To: <20010527181431.A5444@miss.wu-wien.ac.at> 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, Markus Mottl wrote: > Out of curiousity, would it be unsound to allow functions like the > following: > > let f (cmp : 'a -> 'a -> bool) = > let module SomeSet = > Set.Make (struct type t = 'a let compare = cmp end) in > () 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 () I use something very much like that in a few places, for example a "uniquify" function on lists which eliminates duplicates. I ended up creating polymorphic modules for a few of the stdlib modules on account of that old issue about functor instantiations recursive with a type definition, so as to perform the ugly parameterization hack to sidestep this ML limitation, but they are useful elsewhere too. > The compiler complains with: > > File "foo.ml", line 2, characters 49-51: > Unbound type parameter 'a > > This, however, is not true (in any case): 'a is bound by the explicit > function annotation. I thought you could never have type variables on the right hand side if they were'nt also on the left? Besides, currently ML type annotations are without teeth, as you are well aware; as a translator of Okasaki's algorithms you surely miss polymorphic recursion. -- Brian ------------------- To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr