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 KAA00228; Sun, 21 Mar 2004 10:22:23 +0100 (MET) 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 KAA31912 for ; Sun, 21 Mar 2004 10:22:22 +0100 (MET) Received: from swordfish.cs.caltech.edu (swordfish.cs.caltech.edu [131.215.44.124]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i2L9MLHd028802 for ; Sun, 21 Mar 2004 10:22:21 +0100 Received: from orchestra.cs.caltech.edu (orchestra.cs.caltech.edu [131.215.44.20]) by swordfish.cs.caltech.edu (Postfix) with ESMTP id 6502ADF2AB; Sun, 21 Mar 2004 01:22:20 -0800 (PST) Received: by orchestra.cs.caltech.edu (Postfix, from userid 2554) id BBA0E9BBA2; Sun, 21 Mar 2004 01:22:17 -0800 (PST) From: Michael Vanier To: martin_jambon@emailuser.net Cc: caml-list@inria.fr In-reply-to: (message from Martin Jambon on Sun, 21 Mar 2004 16:53:38 +0800 (HKT)) Subject: Re: [Caml-list] extensible records again References: Message-Id: <20040321092217.BBA0E9BBA2@orchestra.cs.caltech.edu> Date: Sun, 21 Mar 2004 01:22:17 -0800 (PST) X-Miltered: at concorde by Joe's j-chkmail ("http://j-chkmail.ensmp.fr")! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; vanier:01 mvanier:01 caml-list:01 extensible:01 2004:99 caml-list:01 vanier:01 compiler:01 mutable:01 mutable:01 int:01 int:01 polymorphic:01 polymorphic:01 caltech:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk X-Status: X-Keywords: X-UID: 281 Interesting. I'll try it. Thanks! Mike > Date: Sun, 21 Mar 2004 16:53:38 +0800 (HKT) > From: Martin Jambon > Cc: caml-list@inria.fr > > On Sat, 20 Mar 2004, Michael Vanier wrote: > > > So I tried this. Aside from the pain of having to change data to 'a data in > > lots of places (which I can live with), I got bitten by the polymorphic > > reference limitation. Specifically, I have a mutable stack of data values > > which became a mutable stack of 'a data values, but the function which > > creates the mutable stack is of type '_a data, so it doesn't type check. I > > can't figure out any way around this. Basically, my main data type _cannot_ > > be parameterized. > > Keep your code polymorphic: create your stack in the same compilation > unit as the full type instanciation. > Then you have to pass your stack as a parameter > to all functions that use it. > > I guess this is more or less what you do: > > (* a.ml *) > let stack = > let st = Stack.create () in > Stack.push (`Int 1) st; > st > (* compiler complains about '_ *) > > > (* b.ml *) > let some_function x = > match Stack.pop stack with > `Int i -> print_int i > | `Custom s -> print_string s > | _ -> () > > > Instead you should write: > > (* a.ml *) > let init_stack () = > let st = Stack.create () in > Stack.push (`Int 1) st; > st > > > (* b.ml *) > let some_function stack x = > match Stack.pop stack with > `Int i -> print_int i > | `Custom s -> print_string s > | _ -> print_float x > > let _ = > let stack = A.init_stack () in > some_function stack 1.2 > > > I hope it answers your question... > > Martin > > ------------------- 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