caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Milan Stanojević" <milanst@gmail.com>
To: Caml List <caml-list@inria.fr>
Subject: [Caml-list] confusing type error when using function with optional arguments
Date: Fri, 16 Nov 2012 09:50:53 -0500	[thread overview]
Message-ID: <CAKR7PS_SqfUDXOzoJ=qkfGpVWU8xfHc1d5uJdWFiiWfkWz=axQ@mail.gmail.com> (raw)

I was playing with %revapply primitive and ran into the following
compiler behavior that I don't understand.

external (|!) : 'a -> ('a -> 'b) -> 'b = "%revapply"

let foo1 ?x ?y () = ()    (* val foo1 : ?x:'a -> ?y:'b -> unit -> unit
*)
let foo2 ?x ?y z = z     (* val foo2 : ?x:'a -> ?y:'b -> 'c -> 'c  *)

let x = () |! foo1   (* compiles just fine *)

let y = () |! foo2   (* fails with
                             Error: This expression has type ?x:'a ->
?y:'b -> 'c -> 'c
                             but an expression was expected of type
unit -> 'd   *)

I don't understand why foo1 is fine and foo2 isn't. I would have
thought that I can use foo2 wherever I can foo1 since it has a
strictly more general type.
Am I missing something obvious here?

%revapply is not important here I just wanted to include context. I
get the same behavior in 3.12.1 and 4.00.1

             reply	other threads:[~2012-11-16 14:51 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-16 14:50 Milan Stanojević [this message]
2012-11-16 15:58 ` Török Edwin
2012-11-16 16:05   ` Milan Stanojević
2012-11-16 16:10     ` Didier Cassirame

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='CAKR7PS_SqfUDXOzoJ=qkfGpVWU8xfHc1d5uJdWFiiWfkWz=axQ@mail.gmail.com' \
    --to=milanst@gmail.com \
    --cc=caml-list@inria.fr \
    /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;
as well as URLs for NNTP newsgroup(s).