From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p7Q9wpku028250 for ; Fri, 26 Aug 2011 11:58:51 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AmcNAJRtV07RVaC2dGdsb2JhbABCnGGLLwgUAQwJDQcPAwYhgUABAQEBAxICJgYBOAEDDAEFBRgcEiETAQUBHAYTIodUnRoKjxCFG4koAgMGgyqCPGAEh2CLOoY1g0KCaDyBRIIw X-IronPort-AV: E=Sophos;i="4.68,284,1312149600"; d="scan'208";a="106699235" Received: from mail-gy0-f182.google.com ([209.85.160.182]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 26 Aug 2011 11:58:49 +0200 Received: by gyd10 with SMTP id 10so3982732gyd.27 for ; Fri, 26 Aug 2011 02:58:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=sender:subject:mime-version:content-type:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to:x-mailer; bh=lBWObaL0hFIHIe1rRKDjiLeZGiED0pC7F5zyJe23qOU=; b=EixdeRf36bDPNqEQTE3rOnACvt+2ZKeE+UZtIGlUZ9GGQljJJcAwPckMhjYSqvnild B+FlekGOBON2DoRGjz9ZjysJvYEplmuFQCwEz1OwTxDIwCqIrQiRwjyhTV7S4QTBlnmb uAh2qzVP9AfzAkPr9xyX5/MAKefNACcLny1r8= Received: by 10.231.65.72 with SMTP id h8mr1915679ibi.47.1314352728028; Fri, 26 Aug 2011 02:58:48 -0700 (PDT) Received: from tet.garrigue.jp (58x158x128x157.ap58.ftth.ucom.ne.jp [58.158.128.157]) by mx.google.com with ESMTPS id es8sm577150ibb.36.2011.08.26.02.58.45 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 26 Aug 2011 02:58:46 -0700 (PDT) Sender: Jacques Garrigue Mime-Version: 1.0 (Apple Message framework v1084) Content-Type: text/plain; charset=us-ascii From: Jacques Garrigue In-Reply-To: Date: Fri, 26 Aug 2011 18:58:43 +0900 Cc: Caml List Message-Id: References: To: Dmitry Bely X-Mailer: Apple Mail (2.1084) Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by walapai.inria.fr id p7Q9wpku028250 Subject: Re: [Caml-list] Labelled parameter bug? On 2011/08/26, at 18:20, Dmitry Bely wrote: > On Wed, Aug 24, 2011 at 7:01 PM, Philippe Veber > wrote: > >>> The following fragment compiles without a warning but produces strange >>> results: >>> >>> let f ?(p1="p1") ~p2 p3 = >>> Printf.printf "p1=%s, p2=%s, p3=%s\n" p1 p2 p3 >>> >>> let _ = >>> f "p2" "p3"; (* 1 *) >>> let f2 = f "p2" in >>> f2 "p3" (* 2 *) > > (...) > >> This first application also applies optional arguments situated before the >> anoymous argument, so it remains the second (labeled) argument only. >> >> There is indeed a special case where you can drop labels if you provide the >> exact number of arguments. This means that f "p2" "p3" is equivalent to f >> ~p2:"p2" "p3". This is written in the manual >> (http://caml.inria.fr/pub/docs/manual-ocaml/manual006.html) : >> >> "As an exception to the above parameter matching rules, if an application is >> total, labels may be omitted. In practice, most applications are total, so >> that labels can be omitted in applications. " >> >> So this is actually the intended behavior, AFAIU > > Indeed. Thanks for the detailed explanation. But shouldn't the > compiler decide that the partial application skipping labeled > parameter is suspicious and generate a warning? The golden rule here is no ambiguity. Since this function accepts only two non-optional arguments (as the return type is unit), if you pass them all at once without labels then this is accepted as a valid full application, and cannot be confused with another interpretation. Note that if you don't like this behaviour, you can manually activate warning 6 (Label omitted in function application) which requires you to write all labels. Jacques Garrigue