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 XAA04307; Wed, 25 Feb 2004 23:56:53 +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 XAA03651 for ; Wed, 25 Feb 2004 23:56:51 +0100 (MET) Received: from mwinf0901.wanadoo.fr (smtp9.wanadoo.fr [193.252.22.22]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i1PMuoae032343 for ; Wed, 25 Feb 2004 23:56:50 +0100 Received: from vanicat.homelinux.org (ca-bordeaux-4-217.w80-8.abo.wanadoo.fr [80.8.76.217]) by mwinf0901.wanadoo.fr (SMTP Server) with ESMTP id 963A918000B7 for ; Wed, 25 Feb 2004 23:56:50 +0100 (CET) Received: from moi by vanicat.homelinux.org with local (Exim 4.30) id 1Aw7xR-0002M1-6K for caml-list@inria.fr; Wed, 25 Feb 2004 23:56:49 +0100 To: caml-list@inria.fr Subject: [Caml-list] Re: Caml-list References to polymorphic variants References: From: Remi Vanicat Mail-Copy-To: never Date: Wed, 25 Feb 2004 23:56:48 +0100 In-Reply-To: (nickgrey@softhome.net's message of "Wed, 25 Feb 2004 09:05:48 -0700") Message-ID: <878yiqu5sf.dlv@vanicat.homelinux.org> User-Agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: 8bit 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; caml-list:01 foo:01 foo:01 variants:01 variants:01 int:01 writes:01 remi:01 remi:01 vanicat:01 vanicat:01 polymorphic:01 polymorphic:01 variant:02 variant:02 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk nickgrey@softhome.net writes: > 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. you can break type safety with your example : `Foo 10 and `Foo "string" are both some polymorphic variant, and if your generalized type would be ok, nothing could forbid you to "convert" one to another, having the same effect that the (Some 1) and (string option) example. -- Rémi Vanicat ------------------- 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