From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 37FED81792 for ; Wed, 10 Jul 2013 17:12:10 +0200 (CEST) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of r.3@libertysurf.fr) identity=pra; client-ip=212.27.42.4; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="r.3@libertysurf.fr"; x-sender="r.3@libertysurf.fr"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of r.3@libertysurf.fr) identity=mailfrom; client-ip=212.27.42.4; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="r.3@libertysurf.fr"; x-sender="r.3@libertysurf.fr"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.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=mail3-smtp-sop.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: AvoAAF553VHUGyoElGdsb2JhbABagkWBQ4MJuxSCc4ETFg4BAQEBBw0JCRQDJYIqIwRtKRkCWYgsmTaOfZEgjy87glaBHwOUAZgzOoFs X-IPAS-Result: AvoAAF553VHUGyoElGdsb2JhbABagkWBQ4MJuxSCc4ETFg4BAQEBBw0JCRQDJYIqIwRtKRkCWYgsmTaOfZEgjy87glaBHwOUAZgzOoFs X-IronPort-AV: E=Sophos;i="4.87,1036,1363129200"; d="scan'208,217";a="20703839" Received: from smtp4-g21.free.fr ([212.27.42.4]) by mail3-smtp-sop.national.inria.fr with ESMTP; 10 Jul 2013 17:12:09 +0200 Received: from zimbra27-e5.priv.proxad.net (unknown [172.20.243.177]) by smtp4-g21.free.fr (Postfix) with ESMTP id B35B04C8177 for ; Wed, 10 Jul 2013 17:12:05 +0200 (CEST) Date: Wed, 10 Jul 2013 17:12:04 +0200 (CEST) From: r.3@libertysurf.fr To: caml-list@inria.fr Message-ID: <307820971.197303711.1373469124430.JavaMail.root@zimbra27-e5.priv.proxad.net> In-Reply-To: <51DD79B6.9030306@libertysurf.fr> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_197303710_243809521.1373469124429" 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_197303710_243809521.1373469124429 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit 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 = You are defining 'f', a function that waits for a labeled argument called 'a' and that will send back itself.
if I apply function f, omiting the label, instead of an error I'll get: # f 12;; - : a:(int -> 'a) -> 'a =
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 :
... 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
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
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 =
This is same behaviour : waiting for a labelled argument that will be able to deal with 5 integers.
It is very confusing...
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 = # 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 ------=_Part_197303710_243809521.1373469124429 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 7bit
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.

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

# f 12;;
- : a:(int -> 'a) -> 'a = <fun>
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 :

... 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

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


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>
This is same behaviour : waiting for a labelled argument that will be able to deal with 5 integers.

It is very confusing...


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
------=_Part_197303710_243809521.1373469124429--