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 8144581792 for ; Wed, 10 Jul 2013 17:05:06 +0200 (CEST) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of alain@frisch.fr) identity=pra; client-ip=193.252.23.212; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="alain@frisch.fr"; x-sender="alain@frisch.fr"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of alain@frisch.fr) identity=mailfrom; client-ip=193.252.23.212; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="alain@frisch.fr"; x-sender="alain@frisch.fr"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@msa.smtpout.orange.fr) identity=helo; client-ip=193.252.23.212; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="alain@frisch.fr"; x-sender="postmaster@msa.smtpout.orange.fr"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AucAABN33VHB/BfUlGdsb2JhbABawiWCc4EpDgEBAQEHDQkJFAMlgiMBAQUnEUARCw4KCRYPCQMCAQIBRQYBDAgBAYgPuVaPaoN1A5dXhiOOOg X-IPAS-Result: AucAABN33VHB/BfUlGdsb2JhbABawiWCc4EpDgEBAQEHDQkJFAMlgiMBAQUnEUARCw4KCRYPCQMCAQIBRQYBDAgBAYgPuVaPaoN1A5dXhiOOOg X-IronPort-AV: E=Sophos;i="4.87,1036,1363129200"; d="scan'208";a="20702480" Received: from msa03.smtpout.orange.fr (HELO msa.smtpout.orange.fr) ([193.252.23.212]) by mail3-smtp-sop.national.inria.fr with ESMTP; 10 Jul 2013 17:05:05 +0200 Received: from [192.168.1.111] ([92.151.124.207]) by mwinf5d52 with ME id yf541l00B4Uby2403f548S; Wed, 10 Jul 2013 17:05:05 +0200 Message-ID: <51DD7820.9090605@frisch.fr> Date: Wed, 10 Jul 2013 17:05:04 +0200 From: Alain Frisch User-Agent: Mozilla/5.0 (X11; Linux i686 on x86_64; rv:23.0) Gecko/20100101 Thunderbird/23.0 MIME-Version: 1.0 To: Ivan Gotovchits , caml-list@inria.fr References: <878v1ea5ky.fsf@golf.niidar.ru> In-Reply-To: <878v1ea5ky.fsf@golf.niidar.ru> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Caml-list] Applying labeled function without a label 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 = > > 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: 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 = # 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