From: Gordon Henriksen <gordonhenriksen@mac.com>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] syntax question
Date: Thu, 29 May 2008 21:54:29 -0400 [thread overview]
Message-ID: <48167D57-C029-4568-B01D-49C00DFE4680@mac.com> (raw)
In-Reply-To: <483F54A5.4020808@cs.caltech.edu>
Michael,
A of a * a is more memory efficient than A of (a * a). In effect, a
variant IS a tuple. If you wish to restrict yourself to restrict
yourself to unary constructors in your programs, you're free to do so
at the cost of extra allocations.
On 2008-05-29, at 21:13, Michael Vanier wrote:
> Adam,
>
> I realize that this is how it works, but I don't understand why it
> should work this way. AFAIK elsewhere in ocaml "int * int" always
> refers to a tuple. Similarly, if testme's Foo really took two int
> arguments I would expect to be able to create Foos as "Foo 1 2"
> instead of "Foo (1, 2)" which looks like Foo takes a single tuple
> argument, not two int arguments. I don't see why "int * int" and
> "(int * int)" are different things.
>
> Mike
>
> Adam Granicz wrote:
>> Hi Michael,
>> In the type definition
>>> # type testme = Foo of int * int;;
>> the constructor Foo takes *two* int arguments (thus, you can not
>> construct a testme value supplying only one argument), whereas in
>>> # type testme2 = Foo2 of (int * int);;
>> it takes *one* tuple argument.
>> Regards,
>> Adam.
>> On Fri, 30 May 2008 00:23:40 +0200, Michael Vanier <mvanier@cs.caltech.edu
>> > wrote:
>>> Hi everyone,
>>>
>>> I got bitten by a simple syntax problem:
>>>
>>> # let a = (1, 2);;
>>> val a : int * int = (1, 2)
>>> # type testme = Foo of int * int;;
>>> type testme = Foo of int * int
>>> # Foo a;;
>>> The constructor Foo expects 2 argument(s),
>>> but is here applied to 1 argument(s)
>>> # Foo (1, 2);;
>>> - : testme = Foo (1, 2)
>>> # type testme2 = Foo2 of (int * int);;
>>> type testme2 = Foo2 of (int * int)
>>> # Foo2 a;;
>>> - : testme2 = Foo2 (1, 2)
>>>
>>> Why does the compiler treat int * int and (int * int) in type
>>> definitions so differently? Is it to give clearer error messages
>>> in the typical case?
>>>
>>> Mike
>>>
>>>
>>>
>>>
>>> _______________________________________________
>>> Caml-list mailing list. Subscription management:
>>> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
>>> Archives: http://caml.inria.fr
>>> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
>>> Bug reports: http://caml.inria.fr/bin/caml-bugs
>> _______________________________________________
>> Caml-list mailing list. Subscription management:
>> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
>> Archives: http://caml.inria.fr
>> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
>> Bug reports: http://caml.inria.fr/bin/caml-bugs
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
Gordon
next prev parent reply other threads:[~2008-05-30 1:54 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-05-29 22:23 Michael Vanier
2008-05-30 0:32 ` [Caml-list] " Adam Granicz
2008-05-30 1:13 ` Michael Vanier
2008-05-30 1:48 ` Adam Granicz
2008-05-30 1:54 ` Gordon Henriksen [this message]
2008-05-30 7:03 ` Christophe TROESTLER
2008-05-30 7:06 ` Luc Maranget
2008-05-30 12:17 ` Damien Doligez
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=48167D57-C029-4568-B01D-49C00DFE4680@mac.com \
--to=gordonhenriksen@mac.com \
--cc=caml-list@yquem.inria.fr \
/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