<?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/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"
  prev="2003/01/881a04377ca8cc96189abbe6f03f111a"
  next="2003/01/b90d9c8752fc9867bb56d0b5f1caabd5"
  prev-in-thread="2003/01/199c38bda63ce2bfd088760b81c5d032"
  next-in-thread="2003/01/d0f4e551ba89f8f7b4b9cfad3f89e3df"
  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>

&gt;  I originally had a very calculation intensive program which used a data
&gt;  type which looked like:
&gt;  
&gt;  &gt; type foo = Foo of float
&gt;  
&gt;  I could just have easily used floats, but I wanted to ensure that I didn't
&gt;  do anything stupid (like try to multiply a foo by a float), so I did this
&gt;  boxing so the type-checker would help me out.

In ocaml, there are no overloaded operations, not automatic
conversions to integers, so that if you don't need to do that at
all. The type system will always force you to use the operations on
floats, or to convert them to foo before multiplying them by foo. 

&gt;  But based on some non-scientific tests, it seems that this isn't the case,
&gt;  and that the original foo type is actually represented using a
&gt;  pointer-to-float.
&gt;  
&gt;  I cannot imagine why this is the case (coming from a Haskell world, there
&gt;  is a difference there between these two types due to laziness, but since
&gt;  ocaml is strict, I figured this wouldn't be the case).

If you want to keep the interface with C simple, you need an
easy/efficient way to move ocaml values between caml functions and C
functions. This is done by specifying the internal representation of
ocaml values so that C functions know how to manipulate them. If you
let the compiler optimize the representation of values, C functions
won't be able to access ocaml values anymore (well, it will be more
complicated, since you need to attach by some way a description of the
representation of each value passed to a C function...).

Of course, it could be done by some annotation, telling the compiler
that the value will never be passed to a C function. But this would
introduce useless complexity into the language.

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

