Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] unboxing of unary datatypes
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-01-14 (00:08)
From: Hal Daume III <hdaume@I...>
Subject: [Caml-list] unboxing of unary datatypes
Hi all,

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

> 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

> 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

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

 - Hal

Hal Daume III

 "Computer science is no more about computers    |
  than astronomy is about telescopes." -Dijkstra |

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: