From: Alain Frisch <Alain.Frisch@inria.fr>
To: louis.gesbert@laposte.net
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Bugs with pattern-matching and exceptions
Date: Tue, 28 Feb 2006 16:51:02 +0100 [thread overview]
Message-ID: <44047166.70308@inria.fr> (raw)
In-Reply-To: <bd9ef41e48da6ab455097a454246dda9@myco.ath.cx>
Louis Gesbert wrote:
> More recently, I discovered a far worse bug which leads to some
> inconsistency. Ocaml offers a syntax " exception E' = E " to create an
> alias to an exception, which I have hardly ever seen used (with reason, it
> seems).
The problem you raise is not related to the "exception E' = E"
construction. E.g.:
# exception E of int;;
exception E of int
# let x = E 1;;
val x : exn = E 1
# exception E of bool;;
exception E of bool
# let y = E true;;
val y : exn = E true
# x = y;;
- : bool = true
Comparing values of different types can be unsafe, I guess, when the
values are custom blocks.
Exception definitions are generative. The equality of two exception
constructors, as checked by pattern matching, is implemented as
reference (pointer) equality. Concretely, the identity of an exception
constructor is a "string ref", whose content corresponds to the
displayed name of the exception. Unfortunately, the generic comparison
function has no way to know that the blocks under consideration are
exceptions and that the constructoes should thus be compared physically.
For equality, this would be quite simple to patch (e.g. reserve a
special GC tag to indicate exception blocks). For the total ordering,
one could e.g. generate a globally unique integer identifier (pointer
comparison does not work because blocks can be moved by the GC).
The other solution is to keep ourselves from using generic comparison
for exceptions and to rely only on pattern matching.
-- Alain
next prev parent reply other threads:[~2006-02-28 15:51 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-02-28 12:29 Louis Gesbert
2006-02-28 15:51 ` Alain Frisch [this message]
2006-03-01 0:03 ` [Caml-list] " Jacques Garrigue
2006-03-01 7:00 ` Alain Frisch
[not found] ` <200602281333.52448.jon@ffconsultancy.com>
2006-03-01 11:10 ` Louis Gesbert
2006-03-01 23:07 Louis Gesbert
2006-03-02 6:47 ` Alain Frisch
2006-03-03 9:02 ` Louis Gesbert
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=44047166.70308@inria.fr \
--to=alain.frisch@inria.fr \
--cc=caml-list@inria.fr \
--cc=louis.gesbert@laposte.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;
as well as URLs for NNTP newsgroup(s).