Browse thread
Constructors are not functions
[
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: | 2009-10-06 (12:19) |
From: | Philippe Wang <philippe.wang.lists@g...> |
Subject: | Re: [Caml-list] Constructors are not functions |
Hello, I don't know the actual reason, but I guess it's simply a choice of semantics. It woud be weird to be able to deconstruct (Bar 42) while not be able to deconstruct (Bar) as it's not constructed. I mean we can write (match x with Bar y -> y). If partial construction were accepted we may like to write (match x with Bar -> x) but we couldn't because Bar is like a function then. With type t = A | B of int what would be the error warning for (match x with A -> 42 | B -> 43) ? Well, then I guess the reason is that it would be complicated to choose some sound enough semantics for partial application of constructors, since the solution of having to write (fun x -> Bar x) is much simpler. If someone has the actual historical explanation, I am also interested. Cheers, Philippe Wang On Tue, Oct 6, 2009 at 2:01 PM, Chantal KELLER <chantal.keller@wanadoo.fr> wrote: > Dear Ocaml users, > > Is there a reason for constructors not to behave like functions? For > instance, one cannot make a partial application from a constructor: > > # type foo = | Bar of int;; > type foo = Bar of int > # let foobar = Bar in foobar 17;; > Error: The constructor Bar expects 1 argument(s), > but is applied here to 0 argument(s) > > Thanks, > -- > Chantal KELLER