From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p0R6DtGO015632 for ; Thu, 27 Jan 2011 07:13:55 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AmcBAH6bQE3UGyoDkWdsb2JhbACkfBUBAQEBCQsKBxEDIYgrszeFTwSMLYNGGw X-IronPort-AV: E=Sophos;i="4.60,384,1291590000"; d="scan'208";a="88510945" Received: from smtp3-g21.free.fr ([212.27.42.3]) by mail2-smtp-roc.national.inria.fr with ESMTP; 27 Jan 2011 07:13:50 +0100 Received: from [192.168.0.10] (unknown [78.192.0.38]) by smtp3-g21.free.fr (Postfix) with ESMTP id 8F6A9A61C2; Thu, 27 Jan 2011 07:13:43 +0100 (CET) Message-ID: <4D410D16.1050700@frisch.fr> Date: Thu, 27 Jan 2011 07:13:42 +0100 From: Alain Frisch User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.13) Gecko/20101207 Lightning/1.0b2 Thunderbird/3.1.7 MIME-Version: 1.0 To: David Allsopp CC: "'Jim Pryor'" , "'caml-list@inria.fr'" References: <20110126221756.GA5907@vaio.jimpryor.net> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Caml-list] Magic with fun (type t) ... ? On 1/26/2011 11:33 PM, David Allsopp wrote: >> # f ();; >> - : exn = E 0 >> # f None;; >> - : exn = E 0 > > # f () = f None;; > - : bool = true There are two distinct problems here, neither of which has been introduced in 3.12. First, the toplevel uses types to display exception arguments only when it knows exactly their type. Otherwise, there is a fallback heuristic to look at runtime tags. # module X : sig val x : exn end = struct exception E of int option let x = E None end;; module X : sig val x : exn end # X.x;; - : exn = X.E 0 Second, exception values values are compared structurally; this means that the constructors are compared textually and when they match, the arguments are compared even if they don't have the same type (yes, this can probably yield to segfaults). # exception E of unit;; exception E of unit # let e1 = E ();; val e1 : exn = E () # exception E of int option;; exception E of int option # let e2 = E None;; val e2 : exn = E None # e1 = e1;; - : bool = true Of course, pattern matching on exceptions uses the true equality between constructors (with a generative semantics). This is only a problem with the generic comparison functions. Cf: http://caml.inria.fr/mantis/view.php?id=1248 http://caml.inria.fr/mantis/view.php?id=4531 http://caml.inria.fr/mantis/view.php?id=4765 http://caml.inria.fr/mantis/view.php?id=5087 Alain