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 SAA12978; Tue, 11 Nov 2003 18:08:25 +0100 (MET) 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 SAA12592 for ; Tue, 11 Nov 2003 18:08:23 +0100 (MET) Received: from mail.speakeasy.net (mail6.speakeasy.net [216.254.0.206]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id hABH8M113957 for ; Tue, 11 Nov 2003 18:08:23 +0100 (MET) Received: (qmail 23237 invoked from network); 11 Nov 2003 17:08:20 -0000 Received: from unknown (HELO grace.speakeasy.net) ([216.254.0.22]) (envelope-sender ) by mail6.speakeasy.net (qmail-ldap-1.03) with AES256-SHA encrypted SMTP for ; 11 Nov 2003 17:08:20 -0000 Date: Tue, 11 Nov 2003 09:08:13 -0800 (PST) From: brogoff@speakeasy.net To: Oleg Trott cc: Jacques Garrigue , "caml-list@inria.fr" Subject: Re: [Caml-list] Strange physical equality behavior In-Reply-To: <200311110148.22096.oleg_trott@columbia.edu> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Loop: caml-list@inria.fr X-Spam: no; 0.00; brogoff:01 caml-list:01 oleg:01 jacques:01 functorial:01 functorial:01 selm:01 ifi:01 val:01 struct:01 pervasives:01 elt:01 3.07:01 pervasives:01 val:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Tue, 11 Nov 2003, Oleg Trott wrote: > On Sunday 09 November 2003 08:33 pm, Jacques Garrigue wrote: > > The functorial approach offers a much cleaner solution. > > I'm not convinced. > > With non-functorial sets: > > type t = Leaf of string | Node of t Set.t > > How would you do this with functorial sets? Perhaps like this: > > http://groups.google.com/groups?selm=fa.dlqsupe.1c6ajga%40ifi.uio.no > > module A : sig > type t = Leaf of string | Node of ASet.t > val compare: t -> t -> int > end > = struct > type t = Leaf of string | Node of ASet.t > let compare t1 t2 = > match (t1, t2) with > (Leaf s1, Leaf s2) -> Pervasives.compare s1 s2 > | (Leaf _, Node _) -> 1 > | (Node _, Leaf _) -> -1 > | (Node n1, Node n2) -> ASet.compare n1 n2 > end > and ASet : Set.S with type elt = A.t > = Set.Make(A) > > (BTW, that example doesn't yet work in 3.07-2 default toplevel. And couldn't > one write "let compare = Pervasives.compare" above? ) module rec A : (* a forgotten "rec" inserted *) sig type t = Leaf of string | Node of ASet.t val compare: t -> t -> int end = struct type t = Leaf of string | Node of ASet.t let compare t1 t2 = match (t1, t2) with (Leaf s1, Leaf s2) -> Pervasives.compare s1 s2 | (Leaf _, Node _) -> 1 | (Node _, Leaf _) -> -1 | (Node n1, Node n2) -> ASet.compare n1 n2 end and ASet : Set.S with type elt = A.t = Set.Make(A) It's a simple syntax error. And, if we use Pervasives.compare, we don't know for sure how the Leaf <-> Node comparison will work, do we? What if it's dependent on the order of occurrence of those constructors in the type definition? Functors can be heavy, but I prefer that approach too. Having a bit of recursiveness in the module language makes them much nicer. Now if we can just get generics... -- Brian ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners