Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Alain Frisch <alain@frisch.fr>
To: David Allsopp <dra-news@metastack.com>
Cc: "'Jim Pryor'" <lists+caml@jimpryor.net>,
	"'caml-list@inria.fr'" <caml-list@inria.fr>
Subject: Re: [Caml-list] Magic with fun (type t) ... ?
Date: Thu, 27 Jan 2011 07:13:42 +0100	[thread overview]
Message-ID: <4D410D16.1050700@frisch.fr> (raw)
In-Reply-To: <E51C5B015DBD1348A1D85763337FB6D9490BA1EA@Remus.metastack.local>

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

  reply	other threads:[~2011-01-27  6:13 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-26 22:17 Jim Pryor
2011-01-26 22:33 ` David Allsopp
2011-01-27  6:13   ` Alain Frisch [this message]
2011-01-27 23:56     ` Guillaume Yziquel
2011-01-26 22:34 ` Jim Pryor
2011-01-26 23:07 ` Guillaume Yziquel
2011-01-26 23:11 ` Gabriel Scherer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4D410D16.1050700@frisch.fr \
    --to=alain@frisch.fr \
    --cc=caml-list@inria.fr \
    --cc=dra-news@metastack.com \
    --cc=lists+caml@jimpryor.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox