caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Goswin von Brederlow <goswin-v-b@web.de>
To: "David Allsopp" <dra-news@metastack.com>
Cc: "'Jon Harrop'" <jon@ffconsultancy.com>, <caml-list@yquem.inria.fr>
Subject: Re: [Caml-list] Constructors are not functions
Date: Thu, 08 Oct 2009 14:37:07 +0200	[thread overview]
Message-ID: <87ljjmxdsc.fsf@frosties.localdomain> (raw)
In-Reply-To: <005501ca468d$dc9b51a0$95d1f4e0$@metastack.com> (David Allsopp's message of "Tue, 6 Oct 2009 15:04:02 +0100")

"David Allsopp" <dra-news@metastack.com> writes:

> Jon Harrop wrote:
>> David Allsopp wrote:
>> > I think it would be possible to simulate the SML behaviour in OCaml
>> > using camlp4 (if you assume that for [type foo = Bar of int] that future
>> > unbound references to [bar] are interpreted as [fun x -> bar x] instead of an
>> > error)
>> 
>> Only if you turned multi-argument type constructors into single-
>> argument ones
>> taking a tuple, i.e. type definitions like:
>> 
>>   type t = Bar of int * int
>> 
>> must become:
>> 
>>   type t = Bar of (int * int)
>
> That's not the case at all - there'd be no reason not to interpret [bar] as [fun x y -> 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...
>
>
> 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 -> t1
t2: int * int -> 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 -> 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 -> int -> t1
t2: int * int -> t2

fun x y -> Bar x y
fun (x,y) -> Foo (x,y)

MfG
        Goswin


  parent reply	other threads:[~2009-10-08 12:42 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-06 12:01 Chantal KELLER
2009-10-06 12:19 ` [Caml-list] " Philippe Wang
2009-10-06 12:38   ` Jon Harrop
2009-10-06 13:38     ` Richard Jones
2009-10-10 11:49     ` blue storm
2009-10-06 12:45 ` David Allsopp
2009-10-06 12:46   ` David Allsopp
2009-10-06 13:14   ` Jim Farrand
2009-10-06 13:51     ` Michel Mauny
2009-10-06 13:15   ` Jon Harrop
2009-10-06 14:04     ` David Allsopp
2009-10-06 14:51       ` Jon Harrop
2009-10-06 15:24       ` Richard Jones
2009-10-06 16:31         ` Jacques Garrigue
2009-10-08 12:37       ` Goswin von Brederlow [this message]
2009-10-09  6:29         ` David Allsopp
2009-10-10  6:16           ` Goswin von Brederlow
2009-10-06 13:18 ` Gerd Stolpmann
2009-10-06 15:50 ` Jérémie Dimino
2009-10-06 21:55   ` blue storm

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ljjmxdsc.fsf@frosties.localdomain \
    --to=goswin-v-b@web.de \
    --cc=caml-list@yquem.inria.fr \
    --cc=dra-news@metastack.com \
    --cc=jon@ffconsultancy.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).