caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Alain Frisch <alain@frisch.fr>
To: Ivan Gotovchits <ivg@ieee.org>, caml-list@inria.fr
Subject: Re: [Caml-list] Applying labeled function without a label
Date: Wed, 10 Jul 2013 17:05:04 +0200	[thread overview]
Message-ID: <51DD7820.9090605@frisch.fr> (raw)
In-Reply-To: <878v1ea5ky.fsf@golf.niidar.ru>

On 07/10/2013 03:48 PM, Ivan Gotovchits wrote:
>
>
> Please, can someone explain the reason behind the following behaviour:
>
>
> # let f ~a = a;;
> val f : a:'a -> 'a = <fun>
>
> if I apply function f, omiting the label, instead of an error I'll get:
>
> # f 12;;
> - : a:(int -> 'a) -> 'a = <fun>
>
> ... a function that accepts a labeled arguments, that is a function from int
> to 'a, and returns a result of this function:

If you apply f without the labeled argument, if means that the 'a in the 
type scheme "a:'a -> 'a" must be a function type accepting 12 (because 
you pass it the value 12).  So 'a is unified with int -> 'b, and the 
type of "f 12" is thus "a:(int -> 'b) -> 'b".

The point to be noted is that omitted labelled arguments are accepted by 
the type-checker and result in a partial application of the function. 
This is different from optional arguments (when omitted in a function 
application with non-labelled arguments, they are assumed to be missing 
and don't result in a partial application).

FWIW, LexiFi's version of OCaml changes this behavior.  We have decided 
that such omitted labelled arguments should be assumed to be really 
missing and thus result in an error, not a partial application.  So in 
our version, we have:

# let f ~a = a;;
val f : a:'a -> 'a = <fun>
# f 12;;
Error: Missing labeled argument ~a in this function call.


This change tends to give better error messages and avoid some 
confusion; it was also necessary to support another local change: 
implicit arguments, which are non-optional labelled arguments that can 
be synthesized by the compiler based on their type.

-- Alain


  parent reply	other threads:[~2013-07-10 15:05 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-10 13:48 Ivan Gotovchits
2013-07-10 15:02 ` John Carr
2013-07-10 15:13   ` r.3
2013-07-10 15:05 ` Alain Frisch [this message]
     [not found] <51DD79B6.9030306@libertysurf.fr>
2013-07-10 15:12 ` r.3

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=51DD7820.9090605@frisch.fr \
    --to=alain@frisch.fr \
    --cc=caml-list@inria.fr \
    --cc=ivg@ieee.org \
    /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).