English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

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: 2001-08-03 (09:19)
From: Andreas Rossberg <rossberg@p...>
Subject: Re: [Caml-list] Why can't I use constructors as functions?
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)
> The former is more natural if you come from an SML background
> (where constructors have 0 or 1 argument), but the latter fits better
> the Caml Light / OCaml execution model, which favors curried
> functions.  By not treating constructors like functions, we avoid
> having to choose...

It seems to me that the former is the only choice that can be
consistently typed.

> - Code clarity.  While using a constructor as a function is sometimes
> convenient, I would argue it is often hard to read.  Writing
> "fun x -> Succ x" is more verbose, but easier to read, I think.

But aren't you basically saying here that currying and partial
application is bad practice? I can think of a person on this list who
will love to hear that but it seems somewhat inconsistent with some of
the basic Caml design decisions... ;-)

Best regards,

	- Andreas

Andreas Rossberg, rossberg@ps.uni-sb.de

"Computer games don't affect kids.
 If Pac Man affected us as kids, we would all be running around in
 darkened rooms, munching pills, and listening to repetitive music."
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