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 JAA19133; Tue, 30 Jul 2002 09:39:19 +0200 (MET DST) 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 JAA19204 for ; Tue, 30 Jul 2002 09:39:19 +0200 (MET DST) Received: from laurelin.dementia.org ([208.167.88.73]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g6U7dIb28015 for ; Tue, 30 Jul 2002 09:39:18 +0200 (MET DST) Received: by laurelin.dementia.org (Postfix, from userid 1001) id B53C170CF; Tue, 30 Jul 2002 03:46:31 -0400 (EDT) To: "Caml-list" Subject: [Caml-list] Serious typechecking error involving new polymorphism (crash) References: <20020729144527.A30919@pauillac.inria.fr> <000f01c2377c$36263060$2097fea9@janxp> From: John Prevost Date: 30 Jul 2002 03:46:31 -0400 (32.397 UMT) In-Reply-To: <000f01c2377c$36263060$2097fea9@janxp> Message-ID: <86vg6xlktk.fsf_-_@laurelin.dementia.org> User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk I've discovered a fairly serious typechecking bug in 3.05. I'm reporting it on the webpage, but also want to mention it here so that people are aware. You can do the following: # type bad = { x : 'a . 'a option ref };; type bad = { x : 'a. 'a option ref; } # let bv = { x = ref None };; val bv : bad = {x = {contents = None}} # bv.x := Some 5;; - : unit = () # let extra_bad = !(bv.x);; val extra_bad : '_a option = Some # f extra_bad;; ***CRASH*** It looks like mutable fields are handled correctly and catch that the value is not, in fact, general enough. But when the mutable field is part of the value (in this case, part of the ref), the check is not done. To be safe, I recommend being very wary of using field types like: 'a . In which values of the type involve mutable portions of type 'a. As long as any mutable portion is not also polymorphic, things are fine. Mutable fields are fine as well, as long as you are careful as described above. As an example, Using mutable x : 'a . 'a option instead of x : 'a . 'a option ref in the above example prevents any poorly typed expressions from appearing. No value may be put in the "good" example except None, since None is the only fully polymorphic option value. John. ------------------- 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