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:13:43 +0200 (CEST)	[thread overview]
Message-ID: <808904221.197306001.1373469223726.JavaMail.root@zimbra27-e5.priv.proxad.net> (raw)
In-Reply-To: <201307101502.r6AF2mcZ007014@outgoing.mit.edu>

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


On 10/07/2013 17:02, John Carr wrote: 

A function with an unconstrained type variable on the right hand side
of its type can potentially take an unlimited number of arguments.

You have the equivalent of a shift-reduce conflict in a grammar.  The
compiler can choose to reduce (apply f to the argument) or shift (save
the arguments waiting for more).  The choice to shift seems odd but
there may be a situation where it is useful.

If your function were defined

let f ~a = a + 0

it would be monomorphic. The compiler would match an unlabeled argument
with parameter a. 


That is to say : 
# let f ~a = a + 0;; 
val f : a:int -> int = <fun> 
# f 12;; 
- : int = 12 


<blockquote>

<blockquote>
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:

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

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>

It is very confusing...

-- 
Caml-list mailing list.  Subscription management and archives: https://sympa.inria.fr/sympa/arc/caml-list Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Bug reports: http://caml.inria.fr/bin/caml-bugs 
</blockquote>

</blockquote>


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

  reply	other threads:[~2013-07-10 15:13 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 [this message]
2013-07-10 15:05 ` Alain Frisch
     [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=808904221.197306001.1373469223726.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).