From: Martin Jambon <martin.jambon@ens-lyon.org>
To: Philippe Veber <philippe.veber@googlemail.com>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Commuting labeled arguments
Date: Sat, 14 Mar 2009 15:43:21 +0100 [thread overview]
Message-ID: <49BBC289.8080908@ens-lyon.org> (raw)
In-Reply-To: <721f7f5a0903140314saf947b9n1531207146ba2e29@mail.gmail.com>
Philippe Veber wrote:
> Hi all,
>
> is this behaviour of the type checker expected ?
>
> Objective Caml version 3.11.0
>
> # let f g x y = g ~x ~y;;
> val f : (x:'a -> y:'b -> 'c) -> 'a -> 'b -> 'c = <fun>
> # let g ~y ~x = x + y;;
> val g : y:int -> x:int -> int = <fun>
> # f g;;
> Error: This expression has type y:int -> x:int -> int
> but is here used with type x:'a -> y:'b -> 'c
>
> If so, I'm tempted to fill a report to mantis anyway, to get this said
> in the manual (i've not seen anything for this case, but i might have
> missed something).
Imagine that any function has a unique runtime representation that only
accepts one particular order for its arguments.
Labeled arguments can only commute during function application when a
particular order is expected. Reordering is done solely by the compiler based
on the presence labels. If no particular order is expected (g ~x ~y in your
definition of f), then the type checker assumes something reasonable but must
make a choice. This is why the first argument of f is inferred to have type
(x:'a -> y:'b -> 'c) although a type annotation could change this.
I find this interesting:
# let f g x y =
g ~x ~y + g ~y ~x
;;
Characters 26-27:
g ~x ~y + g ~y ~x
^
This function is applied to arguments in an order different from other calls.
This is only allowed when the real type is known.
# let f (g : x:_ -> y:_ -> _) x y =
g ~x ~y + g ~y ~x
;;
val f : (x:'a -> y:'b -> int) -> 'a -> 'b -> int = <fun>
Martin
--
http://mjambon.com/
prev parent reply other threads:[~2009-03-14 14:46 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-14 10:14 Philippe Veber
2009-03-14 14:43 ` Martin Jambon [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=49BBC289.8080908@ens-lyon.org \
--to=martin.jambon@ens-lyon.org \
--cc=caml-list@yquem.inria.fr \
--cc=philippe.veber@googlemail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox