<?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/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"
  prev="2003/10/270e39fd60ffa2c8337369bc60b01baf"
  next="2003/10/5c8d3dca064ba4310c8e13954e431d6a"
  prev-in-thread="2003/10/270e39fd60ffa2c8337369bc60b01baf"
  next-in-thread="2003/10/9867fd1f977ffdb30441fe90355a6474"
  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>
Remi Vanicat &lt;vanicat@labri.u-bordeaux.fr&gt; writes:

&gt; "Yaron Minsky" &lt;yminsky@cs.cornell.edu&gt; writes:
&gt;
&gt;&gt; Olivier Andrieu proposed the following code for doing a safe min/max. 
&gt;&gt; Does anyone have any thoughts about this code snippet, and whether it is
&gt;&gt; or is not a safe use of Obj.magic?
&gt;&gt;
&gt;&gt;  let min a b =
&gt;&gt;     let o = Obj.repr a in
&gt;&gt;     if Obj.is_block o &amp;&amp; Obj.tag o = Obj.double_tag
&gt;&gt;     then Obj.magic (fmin (Obj.magic a) (Obj.magic b))
&gt;&gt;     else Pervasives.min a b
&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; 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
&gt; argument.

If you replace 
let i2 = lazy 3;;
by
let i2 = lazy 3.;;

then what I've said became true.

[...]


-- 
Rémi Vanicat
remi.vanicat@laposte.net

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

