<?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/01/0dd0b46584a7a0b466d9c2f5820331a4"
  from="Hal Daume III &lt;hdaume@I...&gt;"
  author="Hal Daume III"
  date="2003-01-14T00:08:37"
  subject="[Caml-list] unboxing of unary datatypes"
  prev="2003/01/04090fa7e7d7b5c29c72124709785397"
  next="2003/01/139e0e1f8dac72a55d31aabe8e5f20ce"
  next-in-thread="2003/01/881a04377ca8cc96189abbe6f03f111a"
  prev-thread="2003/01/047f0a828ed5d8eab79372879e151577"
  next-thread="2003/01/6b3b8aa926b31df45c1942e68097615c"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] unboxing of unary datatypes">
<msg 
  url="2003/01/0dd0b46584a7a0b466d9c2f5820331a4"
  from="Hal Daume III &lt;hdaume@I...&gt;"
  author="Hal Daume III"
  date="2003-01-14T00:08:37"
  subject="[Caml-list] unboxing of unary datatypes">
<msg 
  url="2003/01/881a04377ca8cc96189abbe6f03f111a"
  from="Nicolas Cannasse &lt;warplayer@f...&gt;"
  author="Nicolas Cannasse"
  date="2003-01-14T03:34:45"
  subject="Re: [Caml-list] unboxing of unary datatypes">
<msg 
  url="2003/01/b90d9c8752fc9867bb56d0b5f1caabd5"
  from="Florian Hars &lt;hars@b...&gt;"
  author="Florian Hars"
  date="2003-01-14T11:17:38"
  subject="Re: [Caml-list] unboxing of unary datatypes">
<msg 
  url="2003/01/199c38bda63ce2bfd088760b81c5d032"
  from="Nicolas Cannasse &lt;warplayer@f...&gt;"
  author="Nicolas Cannasse"
  date="2003-01-14T14:12:31"
  subject="Re: [Caml-list] unboxing of unary datatypes">
</msg>
</msg>
</msg>
<msg 
  url="2003/01/88a260e9ef06cf00d42b81f78abfe86d"
  from="Fabrice Le Fessant &lt;fabrice@l...&gt;"
  author="Fabrice Le Fessant"
  date="2003-01-14T10:53:50"
  subject="Re: [Caml-list] unboxing of unary datatypes">
<msg 
  url="2003/01/d0f4e551ba89f8f7b4b9cfad3f89e3df"
  from="Christophe Raffalli &lt;Christophe.Raffalli@u...&gt;"
  author="Christophe Raffalli"
  date="2003-01-14T18:38:09"
  subject="Re: [Caml-list] unboxing of unary datatypes">
</msg>
</msg>
</msg>
</thread>

<contents>
Hi all,

I originally had a very calculation intensive program which used a data
type which looked like:

&gt; type foo = Foo of float

I could just have easily used floats, but I wanted to ensure that I didn't
do anything stupid (like try to multiply a foo by a float), so I did this
boxing so the type-checker would help me out.

I had always assumed that once the code got past the typechecker, the
ocaml compiler would optimize away the constructor, so that the resulting
code would be as efficient as if I had just done

&gt; type foo = float

But based on some non-scientific tests, it seems that this isn't the case,
and that the original foo type is actually represented using a
pointer-to-float.

I cannot imagine why this is the case (coming from a Haskell world, there
is a difference there between these two types due to laziness, but since
ocaml is strict, I figured this wouldn't be the case).

Can someone explain this to me?  Why doesn't the compiler optimize out the
constructor?

 - Hal

--
Hal Daume III

 "Computer science is no more about computers    | hdaume@isi.edu
  than astronomy is about telescopes." -Dijkstra | www.isi.edu/~hdaume

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

