From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id F257581792 for ; Wed, 10 Jul 2013 17:13:48 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of r.3@libertysurf.fr) identity=pra; client-ip=212.27.42.4; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="r.3@libertysurf.fr"; x-sender="r.3@libertysurf.fr"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of r.3@libertysurf.fr) identity=mailfrom; client-ip=212.27.42.4; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="r.3@libertysurf.fr"; x-sender="r.3@libertysurf.fr"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@smtp4-g21.free.fr) identity=helo; client-ip=212.27.42.4; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="r.3@libertysurf.fr"; x-sender="postmaster@smtp4-g21.free.fr"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvoAABt53VHUGyoElGdsb2JhbABagkV2TYMJq2eSIIETFg4BAQEBBw0JCRQDJYIqIwRHJgQhBBkCRxIrh2sDEwiZLY59iEIDiFuPLzsWgkCBHwOZAJM0OoFs X-IPAS-Result: AvoAABt53VHUGyoElGdsb2JhbABagkV2TYMJq2eSIIETFg4BAQEBBw0JCRQDJYIqIwRHJgQhBBkCRxIrh2sDEwiZLY59iEIDiFuPLzsWgkCBHwOZAJM0OoFs X-IronPort-AV: E=Sophos;i="4.87,1036,1363129200"; d="scan'208,217";a="25448812" Received: from smtp4-g21.free.fr ([212.27.42.4]) by mail2-smtp-roc.national.inria.fr with ESMTP; 10 Jul 2013 17:13:47 +0200 Received: from zimbra27-e5.priv.proxad.net (unknown [172.20.243.177]) by smtp4-g21.free.fr (Postfix) with ESMTP id C571A4C8195 for ; Wed, 10 Jul 2013 17:13:44 +0200 (CEST) Date: Wed, 10 Jul 2013 17:13:43 +0200 (CEST) From: r.3@libertysurf.fr To: caml-list@inria.fr Message-ID: <808904221.197306001.1373469223726.JavaMail.root@zimbra27-e5.priv.proxad.net> In-Reply-To: <201307101502.r6AF2mcZ007014@outgoing.mit.edu> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_197306000_749693310.1373469223725" X-Originating-IP: [172.16.79.17, 143.196.127.2] X-Mailer: Zimbra 7.2.0-GA2598 (ZimbraWebClient - FF3.0 (Linux)/7.2.0-GA2598) X-Authenticated-User: r.3@libertysurf.fr Subject: Re: [Caml-list] Applying labeled function without a label ------=_Part_197306000_749693310.1373469223725 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit 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 = # f 12;; - : int = 12
Please, can someone explain the reason behind the following behaviour: # let f ~a = a;; val f : a:'a -> 'a = if I apply function f, omiting the label, instead of an error I'll get: # f 12;; - : a:(int -> 'a) -> 'a = ... 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 = 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
------=_Part_197306000_749693310.1373469223725 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 7bit

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


      
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

    

------=_Part_197306000_749693310.1373469223725--