caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Hal Daume III <hdaume@ISI.EDU>
To: Caml Mailing List <caml-list@inria.fr>
Subject: [Caml-list] unboxing of unary datatypes
Date: Mon, 13 Jan 2003 16:08:32 -0800 (PST)	[thread overview]
Message-ID: <Pine.GSO.4.21.0301131605250.27265-100000@moussor.isi.edu> (raw)

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


             reply	other threads:[~2003-01-14  0:08 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-01-14  0:08 Hal Daume III [this message]
2003-01-14  4:38 ` Nicolas Cannasse
2003-01-14 11:17   ` Florian Hars
2003-01-14 15:15     ` Nicolas Cannasse
2003-01-14  9:57 ` Fabrice Le Fessant
2003-01-14 11:19   ` Christophe Raffalli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.GSO.4.21.0301131605250.27265-100000@moussor.isi.edu \
    --to=hdaume@isi.edu \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).