From: Eric Cooper <ecc@cmu.edu>
To: caml-list@yquem.inria.fr, OCaml <caml-list@inria.fr>
Subject: Re: [Caml-list] Labels and polymorphism
Date: Thu, 8 Mar 2007 14:14:25 -0500 [thread overview]
Message-ID: <20070308191425.GA3724@localhost> (raw)
In-Reply-To: <aee06c9e0703081031o5b5c2a9fy46d7b37e4999a897@mail.gmail.com>
On Thu, Mar 08, 2007 at 10:31:46AM -0800, Nathaniel Gray wrote:
> # let f ~x = x;;
> val f : x:'a -> 'a = <fun>
> # f ~x:1;;
> - : int = 1
> # f 1;;
> - : x:(int -> 'a) -> 'a = <fun>
>
> Can somebody make sense of this for me? Is there a paper somewhere on
> labels in ocaml that I should read?
Section 6.7.1 of the manual, subsection "Function application", says:
As a special case, if the function has a known arity, all the
arguments are unlabeled, and their number matches the number of
non-optional parameters, then labels are ignored and non-optional
parameters are matched in their definition order.
The problem is that if the result type of a function f is 'a, then
it's not of known arity -- an application of f could produce a
function, which could then be applied to more arguments. For example:
# let id x = x;;
val id : 'a -> 'a = <fun>
# id id id id 17;;
- : int = 17
In your example, if you constrain the type of f, it works as expected:
# (f : x:int->int) 1;;
- : int = 1
--
Eric Cooper e c c @ c m u . e d u
next prev parent reply other threads:[~2007-03-08 19:14 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 ` Eric Cooper [this message]
2007-03-08 19:40 ` [Caml-list] " Roland Zumkeller
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=20070308191425.GA3724@localhost \
--to=ecc@cmu.edu \
--cc=caml-list@inria.fr \
--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