From: "Roland Zumkeller" <roland.zumkeller@gmail.com>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Labels and polymorphism
Date: Thu, 8 Mar 2007 20:40:54 +0100 [thread overview]
Message-ID: <d02dcb040703081140v734d3633q1b29cf94c9e66cb@mail.gmail.com> (raw)
In-Reply-To: <aee06c9e0703081031o5b5c2a9fy46d7b37e4999a897@mail.gmail.com>
On 08/03/07, Nathaniel Gray <n8gray@gmail.com> wrote:
> # let f ~x = x;;
> val f : x:'a -> 'a = <fun>
> # f ~x:1;;
> - : int = 1
> # f 1;;
> - : x:(int -> 'a) -> 'a = <fun>
The "1" is assumed to be an argument to "f ~x:a" (where "a" is yet to
be given). Therefore "f ~x:a" must be of type "int -> ...". Now "f
~x:a" is of the same type as (and here actually reduces to) "a".
Hence this type for the x-labeled argument.
Perhaps looking at this might help, too:
# f 1 1 1;;
- : x:(int -> int -> int -> 'a) -> 'a = <fun>
Now you ask, why are things as they are? Why can't OCaml guess that
the "1" was meant for the label "x"?
Probably it could, but with such a typing rule we would have to write
"(fun ~x:a -> f ~x:a 1)" for what is currently "f 1" (partial
application would be essentially lost here). In contrast, becoming
able to write "f x" instead of "f ~x:1" seems not enough of a gain to
compensate this.
Best,
Roland
--
http://www.lix.polytechnique.fr/~zumkeller/
next prev parent reply other threads:[~2007-03-08 19:41 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-03-08 18:31 Nathaniel Gray
2007-03-08 19:14 ` [Caml-list] " Eric Cooper
2007-03-08 19:40 ` Roland Zumkeller [this message]
2007-03-08 23:42 ` Nathaniel Gray
2007-03-19 1:15 ` Jacques Garrigue
2007-03-19 23:53 ` Nathaniel Gray
2007-03-20 0:51 ` Jacques Garrigue
2007-03-08 23:30 ` skaller
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=d02dcb040703081140v734d3633q1b29cf94c9e66cb@mail.gmail.com \
--to=roland.zumkeller@gmail.com \
--cc=caml-list@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