caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: r.3@libertysurf.fr
To: caml-list@inria.fr
Subject: Re: [Caml-list] Applying labeled function without a label
Date: Wed, 10 Jul 2013 17:12:04 +0200 (CEST)	[thread overview]
Message-ID: <307820971.197303711.1373469124430.JavaMail.root@zimbra27-e5.priv.proxad.net> (raw)
In-Reply-To: <51DD79B6.9030306@libertysurf.fr>

[-- Attachment #1: Type: text/plain, Size: 2077 bytes --]


I agree it is very confusing... 


On 10/07/2013 15:48, Ivan Gotovchits wrote: 

Please, can someone explain the reason behind the following behaviour:


# let f ~a = a;;
val f : a:'a -> 'a = <fun> 

You are defining 'f', a function that waits for a labeled argument called 'a' and that will send back itself. 


<blockquote>
if I apply function f, omiting the label, instead of an error I'll get:

# f 12;;
- : a:(int -> 'a) -> 'a = <fun> 
</blockquote>
yes, very confusing. 'f 12' is still not applied (see at the end, it is maybe a problem in ocaml). It is still waiting for the label '~a'. once the label is given, 'f ~a' will be able to give back the result, and then apply it to '12'. So the labelled argument should be a function from an int to something, in order to be applied to '12'. That is what you are doing next : 


<blockquote>
... a function that accepts a labeled arguments, that is a function from int
to 'a, and returns a result of this function:

# f 12 ~a:(fun x -> x + 1);;
- : int = 13 
</blockquote>

What is confusing is that f is applied to ~a, not to 12 directly (because of labels properties). 
f ~a => (fun x -> x+1) 
then 
(fun x -> x +1) 12 => 13 



<blockquote>
and even more, if I apply it to more unlabled arguments:

# f 1 2 3 4 5;;
- : a:(int -> int -> int -> int -> int -> 'a) -> 'a = <fun> 
</blockquote>
This is same behaviour : waiting for a labelled argument that will be able to deal with 5 integers. 


<blockquote>
It is very confusing... 
</blockquote>

I agree it is confusing. And there is something strange : 

The doc says : 

"As an exception to the above parameter matching rules, if an application is total (omitting all optional arguments), labels may be omitted. In practice, many applications are total, so that labels can often be omitted." 
# let f ~x ~y = x - y;; val f : x:int -> y:int -> int = <fun> # f 3 2;; - : int = 1 
But in your case, when you do "f 12", the application is total, and thus it should be applied and give '12'. But it is not applied. This is an inconsistency in the documentation. 

William 

[-- Attachment #2: Type: text/html, Size: 3426 bytes --]

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

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <51DD79B6.9030306@libertysurf.fr>
2013-07-10 15:12 ` r.3 [this message]
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

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=307820971.197303711.1373469124430.JavaMail.root@zimbra27-e5.priv.proxad.net \
    --to=r.3@libertysurf.fr \
    --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;
as well as URLs for NNTP newsgroup(s).