caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Dichotomy between functions and type constructors?
@ 2000-02-18 20:47 David McClain
  2000-02-21 19:31 ` Markus Mottl
  2000-02-25 14:28 ` Xavier Leroy
  0 siblings, 2 replies; 4+ messages in thread
From: David McClain @ 2000-02-18 20:47 UTC (permalink / raw)
  To: caml-list

I am curious about the apparent dichotomy between normal functions and type
constructors, and why this disparity exists?

Say I have a type

type thing =
   T1 of int * float
| ....

I can create such a type as T1(5, 3.14) but I cannot create such a type on a
tuple result of a function call:

let doit x = (x, float_of_int x)

let myT1 = T1(doit x)

This gives rise to a type checking error wherein the constructor T1 demands
two arguments, instead of demanding a tuple of two elements.

SML does not appear to impose this same requirement on the programmer, so
what is the origin of the OCaml requirement?

TIA,

David McClain, Sr. Scientist
Raytheon Systems Co.
Tucson, AZ




^ permalink raw reply	[flat|nested] 4+ messages in thread
* RE: Dichotomy between functions and type constructors?
@ 2000-02-21 18:02 Don Syme
  0 siblings, 0 replies; 4+ messages in thread
From: Don Syme @ 2000-02-21 18:02 UTC (permalink / raw)
  To: 'David McClain', caml-redistribution

I believe it's got something to do with cross module optimization.  However,
I've always wondered why the restriction is not lifted at least inside the
module where the constructor is declared.

Cheers,
Don


-----Original Message-----
From: David McClain [mailto:dmcclain@azstarnet.com]
Sent: 21 February 2000 17:09
To: caml-redistribution@pauillac.inria.fr
Subject: Dichotomy between functions and type constructors?


I am curious about the apparent dichotomy between normal functions and type
constructors, and why this disparity exists?

Say I have a type

type thing =
   T1 of int * float
| ....

I can create such a type as T1(5, 3.14) but I cannot create such a type on a
tuple result of a function call:

let doit x = (x, float_of_int x)

let myT1 = T1(doit x)

This gives rise to a type checking error wherein the constructor T1 demands
two arguments, instead of demanding a tuple of two elements.

SML does not appear to impose this same requirement on the programmer, so
what is the origin of the OCaml requirement?

TIA,

David McClain, Sr. Scientist
Raytheon Systems Co.
Tucson, AZ



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2000-02-25 17:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-02-18 20:47 Dichotomy between functions and type constructors? David McClain
2000-02-21 19:31 ` Markus Mottl
2000-02-25 14:28 ` Xavier Leroy
2000-02-21 18:02 Don Syme

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).