Browse thread
Question on writing efficient Ocaml.
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Nathaniel Gray <n8gray@g...> |
| Subject: | Re: [Caml-list] Question on writing efficient Ocaml. |
On 12/29/06, Mattias Engdegård <mattias@virtutech.se> wrote: > >In general, I wouldn't explicitly advise against using single > >constructor type definitions for documentation, except when the > >argument is a single int or float and performance matters. > > Is there a reason for this? To my innocent eyes, code like > > type length = Length of int > > looks quite reasonable and could be useful at times. I agree. Sadly, the ocaml devs don't. http://caml.inria.fr/mantis/view.php?id=3978 As Xavier points out, one can use modules to hide basic types, but this is pretty clumsy in practice. There's rumored to be a solution using phantom types, but my attempts don't work: # type 'a boink = int;; type 'a boink = int # let f = (20 : string boink);; val f : string boink = 20 # let g = (30 : int boink);; val g : int boink = 30 # f;; - : string boink = 20 # g;; - : int boink = 30 # f + g;; - : int = 50 > If binary compatibility with old OCaml releases would be the reason, > is there a policy stating when such ABI details can be changed? The ocaml devs have been quite clear that the ABI can change at any time, so that's not the reason. Cheers, -n8 -- >>>-- Nathaniel Gray -- Caltech Computer Science ------> >>>-- Mojave Project -- http://mojave.cs.caltech.edu -->