caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Nicolas Cannasse" <warplayer@free.fr>
To: "Hal Daume III" <hdaume@ISI.EDU>,
	"Caml Mailing List" <caml-list@inria.fr>
Subject: Re: [Caml-list] unboxing of unary datatypes
Date: Tue, 14 Jan 2003 04:38:13 -0000	[thread overview]
Message-ID: <001301c2bb7e$5e119840$41da0e50@warp> (raw)
In-Reply-To: <Pine.GSO.4.21.0301131605250.27265-100000@moussor.isi.edu>

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

Hi,

What you might need here are shadow types.
You can define in your ML source file:

type foo = float
let mfoo f f' = f *. f' (* or better let mfoo = ( *. ) *)

and in your interface ( MLI file ) :

type foo
val mfoo : foo -> foo -> foo

then, other modules trying to work with your foo will have to use your set
of operators because they won't know what exactly is "foo".

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

Because they don't have the same C raw representation.
There is one more indirection when you use a constructor.
If you want to interface OCaml with C, you have to be sure that the compiler
won't try to optimize things in an incompatible way ( that goes for all
compilers I think... )

Nicolas Cannasse

-------------------
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  3:34 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-01-14  0:08 Hal Daume III
2003-01-14  4:38 ` Nicolas Cannasse [this message]
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='001301c2bb7e$5e119840$41da0e50@warp' \
    --to=warplayer@free.fr \
    --cc=caml-list@inria.fr \
    --cc=hdaume@ISI.EDU \
    /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).