<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2009/10/f264a933b70853017a592acf45adc39f"
  from="Goswin von Brederlow &lt;goswin-v-b@w...&gt;"
  author="Goswin von Brederlow"
  date="2009-10-08T12:42:14"
  subject="Re: [Caml-list] Constructors are not functions"
  prev="2009/10/0e9c7e2ae6689422e1e9d874cd8f3816"
  next="2009/10/5d8af1da433fb68c732a6e6ec72601ca"
  prev-in-thread="2009/10/b12df86f3d2ae39913e2e3a9d6a2afd5"
  next-in-thread="2009/10/2f4e4d057ce5bb361d58ef7ac98d95e5"
  prev-thread="2009/10/c0015c890b908f272c4dc603b1de268a"
  next-thread="2009/10/f4c2db533557676eb31a47d6e4761518"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="Constructors are not functions">
<msg 
  url="2009/10/c52bdaf88a932ffd02a17cf12e7a6843"
  from="Chantal KELLER &lt;chantal.keller@w...&gt;"
  author="Chantal KELLER"
  date="2009-10-06T12:01:35"
  subject="Constructors are not functions">
<msg 
  url="2009/10/198f097943e995b4154915c479f6241d"
  from="Philippe Wang &lt;philippe.wang.lists@g...&gt;"
  author="Philippe Wang"
  date="2009-10-06T12:19:59"
  subject="Re: [Caml-list] Constructors are not functions">
<msg 
  url="2009/10/3d94477a1248c4ea3e9b3796fbd96b30"
  from="Jon Harrop &lt;jon@f...&gt;"
  author="Jon Harrop"
  date="2009-10-06T12:37:38"
  subject="Re: [Caml-list] Constructors are not functions">
<msg 
  url="2009/10/8f4a51ef46e423a76ca1a9b355516591"
  from="Richard Jones &lt;rich@a...&gt;"
  author="Richard Jones"
  date="2009-10-06T13:39:01"
  subject="Re: [Caml-list] Constructors are not functions">
</msg>
<msg 
  url="2009/10/e8e36f42040a988ae01a1722a9058a0c"
  from="blue storm &lt;bluestorm.dylc@g...&gt;"
  author="blue storm"
  date="2009-10-10T11:49:25"
  subject="Re: [Caml-list] Constructors are not functions">
</msg>
</msg>
</msg>
<msg 
  url="2009/10/0943a75983cb128775e51daec525fc91"
  from="David Allsopp &lt;dra-news@m...&gt;"
  author="David Allsopp"
  date="2009-10-06T12:45:10"
  subject="RE: [Caml-list] Constructors are not functions">
<msg 
  url="2009/10/9786fb19966b2a45500aaecdb3f831a9"
  from="David Allsopp &lt;dra-news@m...&gt;"
  author="David Allsopp"
  date="2009-10-06T12:46:57"
  subject="RE: [Caml-list] Constructors are not functions">
</msg>
<msg 
  url="2009/10/313b39775708cfcfea942296fb5480ba"
  from="Jim Farrand &lt;jim.farrand@g...&gt;"
  author="Jim Farrand"
  date="2009-10-06T13:14:37"
  subject="Re: [Caml-list] Constructors are not functions">
<msg 
  url="2009/10/3e23a32f43714fe2aaa93dba667b511f"
  from="Michel Mauny &lt;Michel.Mauny@i...&gt;"
  author="Michel Mauny"
  date="2009-10-06T13:50:29"
  subject="Re: [Caml-list] Constructors are not functions">
</msg>
</msg>
<msg 
  url="2009/10/aba0d7c29944654db93a75ba9f263e53"
  from="Jon Harrop &lt;jon@f...&gt;"
  author="Jon Harrop"
  date="2009-10-06T13:15:08"
  subject="Re: [Caml-list] Constructors are not functions">
<msg 
  url="2009/10/fe2ab6fd1ea44b59605e06017966efe8"
  from="David Allsopp &lt;dra-news@m...&gt;"
  author="David Allsopp"
  date="2009-10-06T14:04:08"
  subject="RE: [Caml-list] Constructors are not functions">
<msg 
  url="2009/10/7ba4d13d6fa24170cbd8758b6cd063b3"
  from="Jon Harrop &lt;jon@f...&gt;"
  author="Jon Harrop"
  date="2009-10-06T14:50:46"
  subject="Re: [Caml-list] Constructors are not functions">
</msg>
<msg 
  url="2009/10/ccb202ae118dbc3a11bb5a89174e5551"
  from="Richard Jones &lt;rich@a...&gt;"
  author="Richard Jones"
  date="2009-10-06T15:24:10"
  subject="Re: [Caml-list] Constructors are not functions">
<msg 
  url="2009/10/b12df86f3d2ae39913e2e3a9d6a2afd5"
  from="Jacques Garrigue &lt;garrigue@m...&gt;"
  author="Jacques Garrigue"
  date="2009-10-06T16:31:44"
  subject="Re: [Caml-list] Constructors are not functions">
</msg>
</msg>
<msg 
  url="2009/10/f264a933b70853017a592acf45adc39f"
  from="Goswin von Brederlow &lt;goswin-v-b@w...&gt;"
  author="Goswin von Brederlow"
  date="2009-10-08T12:42:14"
  subject="Re: [Caml-list] Constructors are not functions">
<msg 
  url="2009/10/2f4e4d057ce5bb361d58ef7ac98d95e5"
  from="David Allsopp &lt;dra-news@m...&gt;"
  author="David Allsopp"
  date="2009-10-09T06:29:55"
  subject="RE: [Caml-list] Constructors are not functions">
<msg 
  url="2009/10/e7f2f5d4e0ff800e2527d4e93fdbed96"
  from="Goswin von Brederlow &lt;goswin-v-b@w...&gt;"
  author="Goswin von Brederlow"
  date="2009-10-10T06:25:27"
  subject="Re: [Caml-list] Constructors are not functions">
</msg>
</msg>
</msg>
</msg>
</msg>
</msg>
<msg 
  url="2009/10/94e682caf3469295724fbd74aa679dbb"
  from="Gerd Stolpmann &lt;gerd@g...&gt;"
  author="Gerd Stolpmann"
  date="2009-10-06T13:13:51"
  subject="Re: [Caml-list] Constructors are not functions">
</msg>
<msg 
  url="2009/10/eef410c2123f8a267621dfdc8c2c22da"
  from="Jérémie Dimino &lt;jeremie@d...&gt;"
  author="Jérémie Dimino"
  date="2009-10-06T15:51:01"
  subject="Re: [Caml-list] Constructors are not functions">
<msg 
  url="2009/10/9b4d5d1a9bf77b85b658129d148e5d03"
  from="blue storm &lt;bluestorm.dylc@g...&gt;"
  author="blue storm"
  date="2009-10-06T21:55:17"
  subject="Re: [Caml-list] Constructors are not functions">
</msg>
</msg>
</msg>
</thread>

<contents>
"David Allsopp" &lt;dra-news@metastack.com&gt; writes:

&gt; Jon Harrop wrote:
&gt;&gt; David Allsopp wrote:
&gt;&gt; &gt; I think it would be possible to simulate the SML behaviour in OCaml
&gt;&gt; &gt; using camlp4 (if you assume that for [type foo = Bar of int] that future
&gt;&gt; &gt; unbound references to [bar] are interpreted as [fun x -&gt; bar x] instead of an
&gt;&gt; &gt; error)
&gt;&gt; 
&gt;&gt; Only if you turned multi-argument type constructors into single-
&gt;&gt; argument ones
&gt;&gt; taking a tuple, i.e. type definitions like:
&gt;&gt; 
&gt;&gt;   type t = Bar of int * int
&gt;&gt; 
&gt;&gt; must become:
&gt;&gt; 
&gt;&gt;   type t = Bar of (int * int)
&gt;
&gt; That's not the case at all - there'd be no reason not to interpret [bar] as [fun x y -&gt; Bar(x, y)] for [Bar of int * int]. What would be hairy in camlp4 would be having to read .cmi files to deal with types defined outside your source file, but that's still not impossible...
&gt;
&gt;
&gt; David 

Then what about

type t1 = Bar of int * int
type t2 = Foo of (int * int)

If you treat constructors as functions taking one argument then

t1: int * int -&gt; t1
t2: int * int -&gt; t2

But:

# let x = (1,2);;
val x : int * int = (1, 2)
# Foo(x);;
- : t2 = Foo (1, 2)
# Bar(x);;
Error: The constructor Bar expects 2 argument(s),
       but is here applied to 1 argument(s)

As functions "Bar" would have to deconstruct the tuple while "Foo"
uses it directly. And I would rather have curried constructors as in
"Bar 1 : int -&gt; t1".


The difference between t1 and t2 gets lost. I actually hate that you
can write "Bar(1,2)" and "Foo(1,2)" Same problem there. It is unclear
if you pass 2 arguments or a tuple.

This should really be

t1: int -&gt; int -&gt; t1
t2: int * int -&gt; t2

fun x y -&gt; Bar x y
fun (x,y) -&gt; Foo (x,y)

MfG
        Goswin

</contents>

</message>

