Version française
Home     About     Download     Resources     Contact us    
Browse thread
Parameter evaluation order
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jon Harrop <jon@f...>
Subject: Re: [Caml-list] Re: Parameter evaluation order
On Wednesday 24 August 2005 21:25, brogoff wrote:
> > I would prefer square bracket for constructor application, mandatory
> > even for unary constructor (and maybe also constant constructor then you
> > can lift the restriction about capital letter)

It would be nice if variant constructors were functions (as they are in SML, 
IIRC). So you could do this:

# type num = Int of int | Float of float;;
type num = Int of int | Float of float
# List.map Int [1; 2; 3];;
- : num list = [Int 1; Int 2; Int 3]

Rather than having to do "List.map (fun i -> Int i) ...". That wouldn't work 
with polymophic variants though, at least not trivially.

If variant constructors always accepted a single, tuple argument could it not 
be optimised away in most cases? Also, could constructors be curried instead 
of using tuples (or syntax that looks like tuples)?

> The examples that bother me most are record constructors, where I want to
> read structured data from a file into a record. And of course :: (which is
> just sugar) too.

Yes. It would be nice if (fun h t -> h::t) could be written infix as ( :: ), 
as operators are. In fact, couldn't that be added without breaking backward 
compatibility?

> It's a fun topic to chat about, but if you were allowed one change in the
> language, surely this wouldn't be it? :-)

Good question. :-)

-- 
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
Objective CAML for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists