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 JAA31352; Sun, 21 Mar 2004 09:55:16 +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 JAA31038 for ; Sun, 21 Mar 2004 09:55:15 +0100 (MET) Received: from out2.smtp.messagingengine.com (out2.smtp.messagingengine.com [66.111.4.26]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i2L8tkKW019165 for ; Sun, 21 Mar 2004 09:55:47 +0100 X-Sasl-enc: e/SeldmfRhbjiovQTnXJNg 1079859226 Received: from [192.168.1.100] (unknown [218.81.124.246]) by mail.messagingengine.com (Postfix) with ESMTP id F04557DBB04; Sun, 21 Mar 2004 03:53:44 -0500 (EST) Date: Sun, 21 Mar 2004 16:53:38 +0800 (HKT) From: Martin Jambon X-X-Sender: martin@localhost To: Michael Vanier Cc: caml-list@inria.fr Subject: Re: [Caml-list] extensible records again In-Reply-To: <20040321062143.BE7D29BBA2@orchestra.cs.caltech.edu> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Miltered: at nez-perce by Joe's j-chkmail ("http://j-chkmail.ensmp.fr")! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 extensible:01 vanier:01 compiler:01 mutable:01 mutable:01 int:01 int:01 polymorphic:01 polymorphic:01 match:02 match:02 float:02 stack:02 stack:02 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk X-Status: X-Keywords: X-UID: 279 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