Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Why can't I use constructors as functions?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Markus Mottl <markus@m...>
Subject: Re: [Caml-list] Why can't I use constructors as functions?
On Fri, 03 Aug 2001, Xavier Leroy wrote:
> - Constructors in Caml Light and OCaml really have an arity, e.g.
> C of int * int is really a constructor with two integer arguments,
> not a constructor taking one argument that is a pair.  Hence, there
> would be two ways to map the constructor C to a function:
>         fun (x,y) -> C(x,y)
> or
>         fun x y -> C(x,y)

Why? To me only the latter seems to be consistent with the
constructor. I'd expect the first form in the case of "C of (int * int)",
which is indeed represented differently to "C of int * int".

Actually, this proves that we already have ambiguity, e.g.:

  C (1, 2)

How does the definition of this variant look like?

  C of int * int

or

  C of (int * int)

?

Nobody can tell...

Therefore, I'd rather propose that it be required to write:

  C 1 2

if the definition is "C of int * int". I know, this would break a lot
(maybe almost all) code, but could be automatically transformed if
required. Maybe the choice of the type constructor for pairs "*" wasn't
so good: people really confuse this with tuples. Another symbol would
seem more approriate ("&", "^", ...?).

The language would seem much more regular to me if functions and
constructors were treated in a similar way.  Would this be too big a
change to the core language?

Regards,
Markus Mottl

-- 
Markus Mottl                                             markus@oefai.at
Austrian Research Institute
for Artificial Intelligence                  http://www.oefai.at/~markus
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr