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
Constructors are not functions
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2009-10-06 (12:37)
From: Jon Harrop <jon@f...>
Subject: Re: [Caml-list] Constructors are not functions
On Tuesday 06 October 2009 13:19:58 Philippe Wang wrote:
> 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.

Can you not just say that Bar in an expression is a function (fun x -> Bar x)?

Dr Jon Harrop, Flying Frog Consultancy Ltd.