<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2006/02/f59cbd9f9ad173f62257c0a2417724b6"
  from="Alain Frisch &lt;Alain.Frisch@i...&gt;"
  author="Alain Frisch"
  date="2006-02-28T15:51:12"
  subject="Re: [Caml-list] Bugs with pattern-matching and exceptions"
  prev="2006/02/810a676239033685940f34f8c4924ab8"
  next="2006/02/9be4a9513b06eceb470e19b33ee11f97"
  prev-in-thread="2006/03/822d2f2c3d1af7ac9e0082045e99c1a4"
  prev-thread="2006/02/8fc9c1a56c497b9743515a5e3432d704"
  next-thread="2006/02/5a06bc8279f4c19275cafe9ac3e9a815"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="Bugs with pattern-matching and exceptions">
<msg 
  url="2006/02/14a9c4cad7029f82e8818777b3f1896f"
  from="Louis Gesbert &lt;louis.gesbert@l...&gt;"
  author="Louis Gesbert"
  date="2006-02-28T12:30:26"
  subject="Bugs with pattern-matching and exceptions">
<msg 
  url="2006/03/4398675b8454295704c29c665a64f6d8"
  from="Jacques Garrigue &lt;garrigue@m...&gt;"
  author="Jacques Garrigue"
  date="2006-03-01T00:05:53"
  subject="Re: [Caml-list] Bugs with pattern-matching and exceptions">
<msg 
  url="2006/03/627e09e63f78283e4be03da71aabf3ad"
  from="Alain Frisch &lt;Alain.Frisch@i...&gt;"
  author="Alain Frisch"
  date="2006-03-01T07:00:50"
  subject="Re: [Caml-list] Bugs with pattern-matching and exceptions">
</msg>
</msg>
<msg 
  url="2006/03/822d2f2c3d1af7ac9e0082045e99c1a4"
  from="Louis Gesbert &lt;louis.gesbert@l...&gt;"
  author="Louis Gesbert"
  date="2006-03-01T11:10:30"
  subject="Re: [Caml-list] Bugs with pattern-matching and exceptions">
</msg>
<msg 
  url="2006/02/f59cbd9f9ad173f62257c0a2417724b6"
  from="Alain Frisch &lt;Alain.Frisch@i...&gt;"
  author="Alain Frisch"
  date="2006-02-28T15:51:12"
  subject="Re: [Caml-list] Bugs with pattern-matching and exceptions">
</msg>
</msg>
</thread>

<contents>
Louis Gesbert wrote:
&gt; More recently, I discovered a far worse bug which leads to some
&gt; inconsistency. Ocaml offers a syntax " exception E' = E " to create an
&gt; alias to an exception, which I have hardly ever seen used (with reason, it
&gt; 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

</contents>

</message>

