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 RAA19273; Wed, 25 Feb 2004 17:33:50 +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 RAA16835 for ; Wed, 25 Feb 2004 17:33:49 +0100 (MET) From: nickgrey@softhome.net Received: from jive.SoftHome.net (jive.SoftHome.net [66.54.152.27]) by nez-perce.inria.fr (8.12.10/8.12.10) with SMTP id i1PGXnIq028490 for ; Wed, 25 Feb 2004 17:33:50 +0100 Received: (qmail 28183 invoked by uid 417); 25 Feb 2004 16:32:39 -0000 Received: from mambo-.softhome.net (HELO softhome.net) (172.16.2.15) by shunt-smtp-out-0 with SMTP; 25 Feb 2004 16:32:39 -0000 Received: from localhost (localhost [127.0.0.1]) (uid 417) by softhome.net with local; Wed, 25 Feb 2004 09:05:48 -0700 To: caml-list@inria.fr Subject: [Caml-list] References to polymorphic variants Date: Wed, 25 Feb 2004 09:05:48 -0700 Mime-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Sender: nickgrey@softhome.net X-Originating-IP: [81.178.226.3] Message-ID: 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; variants:01 variants:01 int:01 polymorphic:01 polymorphic:01 variant:02 variant:02 compile:02 arbitrary:02 string:03 string:03 contexts:03 variable:03 types:03 let:04 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hi, I want to be able to store an arbitrary polymorphic variant in a reference: let (x : ([> ] option) ref ) = ref None ;; (Not my actual code, I've boiled it down to a minimal example.) This won't compile because it "contains a type variable which cannot be generalized". I understand this error message in other contexts. If my code were let x = ref None then I could break type safety by putting (Some 1) into the reference, and later reading the reference with type (string option) thus casting a string to an int. But as I'm dealing with a polymorphic variant, surely this should not apply. My understanding of polymorphic variants is that you do not need to specify at the time of declaration what types it might contain. So, what am I doing wrong and how can I get around it? Regards, Nick ------------------- 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