<?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="2003/10/9867fd1f977ffdb30441fe90355a6474"
  from="Jacques Garrigue &lt;garrigue@k...&gt;"
  author="Jacques Garrigue"
  date="2003-10-16T01:13:45"
  subject="Re: [Caml-list] NaN-safe min and max"
  prev="2003/10/1d9068e72e43c01e47fd636092c357a2"
  next="2003/10/90e8b164cd4c59cbdc4d97b85ddea4e6"
  prev-in-thread="2003/10/356d8db8c34fb8ca1c896dcb3fd55920"
  prev-thread="2003/10/702773fd728055d4a47e1db53ea3cc20"
  next-thread="2003/10/5c8d3dca064ba4310c8e13954e431d6a"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] NaN-safe min and max">
<msg 
  url="2003/10/edeefa11537d0dda03680616cfa6a82f"
  from="Yaron Minsky &lt;yminsky@c...&gt;"
  author="Yaron Minsky"
  date="2003-10-15T14:52:09"
  subject="[Caml-list] NaN-safe min and max">
<msg 
  url="2003/10/270e39fd60ffa2c8337369bc60b01baf"
  from="Remi Vanicat &lt;vanicat@l...&gt;"
  author="Remi Vanicat"
  date="2003-10-15T17:03:31"
  subject="Re: [Caml-list] NaN-safe min and max">
<msg 
  url="2003/10/356d8db8c34fb8ca1c896dcb3fd55920"
  from="Remi Vanicat &lt;vanicat@l...&gt;"
  author="Remi Vanicat"
  date="2003-10-15T18:59:18"
  subject="Re: [Caml-list] NaN-safe min and max">
</msg>
<msg 
  url="2003/10/9867fd1f977ffdb30441fe90355a6474"
  from="Jacques Garrigue &lt;garrigue@k...&gt;"
  author="Jacques Garrigue"
  date="2003-10-16T01:13:45"
  subject="Re: [Caml-list] NaN-safe min and max">
</msg>
</msg>
</msg>
</thread>

<contents>
From: Remi Vanicat &lt;vanicat@labri.u-bordeaux.fr&gt;

&gt; this one is unsafe : the fact that a is a block with a tag
&gt; Obj.double_tag doesn't proof that the same is true for b even if a and
&gt; b have the same type :
&gt; 
&gt; # let i1 = Lazy.lazy_from_val 0.0;;
&gt; val i1 : float Lazy.t = lazy 0.
&gt; # let o1 = Obj.repr i1;;
&gt; val o1 : Obj.t = &lt;abstr&gt;
&gt; # Obj.is_block o1;;
&gt; - : bool = true
&gt; # Obj.tag o1 = Obj.double_tag;;
&gt; - : bool = true
&gt; # let i2 = lazy 3;;
&gt; val i2 : int lazy_t = &lt;lazy&gt;
&gt; # let o2 = Obj.repr i2;;
&gt; val o2 : Obj.t = &lt;abstr&gt;
&gt; # Obj.is_block o2;;
&gt; - : bool = true
&gt; #  Obj.tag o2 = Obj.double_tag;;
&gt; - : bool = false
&gt; 
&gt; both i1 and i2 have the same type, but only the first one is a block of
&gt; tag Obj.double_tag. A verification have to be done for both argument.

Very interesting: you have found an unsoundness in the ocaml compiler.
Using your example combined with arrays we obtain:

# let arr = [|Lazy.lazy_from_val 0.0; lazy 1.0|];;
val arr : float Lazy.t array = [|lazy 0.; lazy 4.32681603021051e-311|]

i.e., the second lazy is assumed to be a float value, and results in a
wrong result (clearly 1.0 is not anything close to 4.32e-311)

So my take on this is that the code suggested for min is correct, this
is the compiler which is wrong: two values with the same type _must_
have the same representation.

A new headache for implementers...

   Jacques Garrigue

-------------------
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

</contents>

</message>

