Browse thread
[Caml-list] Why can't I use constructors as functions?
-
Krishnaswami, Neel
-
Xavier Leroy
- Andreas Rossberg
- Markus Mottl
- Marcin 'Qrczak' Kowalczyk
-
Xavier Leroy
[
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: | 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