From mboxrd@z Thu Jan 1 00:00:00 1970 X-Sympa-To: caml-list@inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p7OF294t008176 for ; Wed, 24 Aug 2011 17:02:09 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AhgCAFERVU7RVdQ2kGdsb2JhbABCmC2HOwGIBggUAQEBAQkJDQcUBCGBQAEBAQECARICExkBGxILAQMBCwYFBAcaISEBAREBBQEKEgYTCAoQh08EniIKjDmCVYVCO4htAgMGhkMEglGQSIl3gmU8g2U X-IronPort-AV: E=Sophos;i="4.68,275,1312149600"; d="scan'208";a="117036890" Received: from mail-vw0-f54.google.com ([209.85.212.54]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 24 Aug 2011 17:02:04 +0200 Received: by vws18 with SMTP id 18so1955664vws.27 for ; Wed, 24 Aug 2011 08:02:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=mQ9HdRhQC7VfFA5C/Q7tuz2E43ZfaJUcrkE20BLpVcY=; b=HTOQw7lAuFneYZOGJMrCWWP2ZRHt9wCr+RqQP2z0i5u8HE2vaYCbhL3hHMr08Ji1x9 2USG/v32IUwcEovQd56a3BYCWZPYlcfaVkyYGtsFDE7TSioF/pl1uowom5tqCV61V3ii k2LqUQntBVUD+HuFj4lup6F5bl2GPesjXLCG0= Received: by 10.220.208.21 with SMTP id ga21mr1638569vcb.88.1314198122768; Wed, 24 Aug 2011 08:02:02 -0700 (PDT) MIME-Version: 1.0 Received: by 10.220.74.67 with HTTP; Wed, 24 Aug 2011 08:01:41 -0700 (PDT) In-Reply-To: References: From: Philippe Veber Date: Wed, 24 Aug 2011 17:01:41 +0200 Message-ID: To: Dmitry Bely Cc: Caml List Content-Type: multipart/alternative; boundary=00235452f63045a95e04ab4198a5 X-Validation-by: philippe.veber@gmail.com Subject: Re: [Caml-list] Labelled parameter bug? --00235452f63045a95e04ab4198a5 Content-Type: text/plain; charset=ISO-8859-1 Hello, 2011/8/24 Dmitry Bely > 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 *) > The type of f is val f : ?p1:string -> p2:string -> string -> unit = so f "p2" applies to the only anonymous parameter (third one) because it cannot be applied to the first or second without label : # f "p2";; - : p2:string -> unit = 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 Philippe. > > Outputs: > > p1=p1, p2=p2, p3=p3 (1) > p1=p1, p2=p3, p3=p2 (2) > > Why (1) and (2) are different? I assume f "p2" takes p3 instead of p2 > but then the compiler should issue at least a warning... > > - Dmitry Bely > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa-roc.inria.fr/wws/info/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > > --00235452f63045a95e04ab4198a5 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hello,

2011/8/24 Dmitry Bely <dmitry.bely@gmail.com>
The following fragment compiles without a warning but produces strange resu= lts:

let f ?(p1=3D"p1") ~p2 p3 =3D
=A0Printf.printf "p1=3D%s, p2=3D%s, p3=3D%s\n" p1 p2 p3

let _ =3D
=A0f "p2" "p3"; (* 1 *)
=A0let f2 =3D f "p2" in
=A0f2 "p3" (* 2 *)

The type of f is
val f : ?p1:string -> p2:string -> string -> unit =3D <fun= >

so f "p2" applies to the only anonymous parameter (th= ird one) because it cannot be applied to the first or second without label = :

# f "p2";;
- : p2:string -> unit =3D <fun>
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&q= uot; is equivalent to f ~p2:"p2" "p3". This is written = in the manual (
http://caml.inria.fr/pub/docs/manual-ocaml/manual006.html) :<= br>
"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 appli= cations. "

So this is actually the intended behavior, AFAIU

Phili= ppe.

=A0

Outputs:

p1=3Dp1, p2=3Dp2, p3=3Dp3 (1)
p1=3Dp1, p2=3Dp3, p3=3Dp2 (2)

Why (1) and (2) are different? I assume f "p2" takes p3 instead o= f p2
but then the compiler should issue at least a warning...

- Dmitry Bely

--
Caml-list mailing list. =A0Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


--00235452f63045a95e04ab4198a5--