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] Constructors as functions and tuples in constructors
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Nicolas Cannasse <warplayer@f...>
Subject: Re: [Caml-list] Constructors as functions and tuples in constructors
> Gentlemen!
> There are two features, which might it be useful to support in the
> language w/out modifying it much. And they both are about greater
> generality of the language.
> First, it would be nice to have constructors as functions like below:
> List. map Some [17]

This is only syntaxic sugar. First class constructors are easy to add to the
language, that's just a matter of will from the INRIA team to choose to add
it or not ( meaning : since they didn't put the feature in the language yet,
they might have good reasons to do so. ).

> Second, it would also be nice not to have "the concept of constructor
> arity", and treat the code below as correct:
> type t = A of int * int
> let _ =
>   match A (17, 0) with
>     A z -> match z with (x, y) -> ()
> Does anybody know, whether this is possible? Or, if not, what are the
> prohibiting reasons?

This is possible :
type t = A of (int * int)

Notice the difference :
- in the first case, you alloc a block with tag "A" of size 2
- in the second, you alloc a block with tag "A" of size 1 containing a tuple
(a block of size 2 with tag 0 containing the two ints). There is then one
more indirection in your integers access but the tuple can be returned
directly without any added allocation.

Nicolas Cannasse

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