caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: bluestorm <bluestorm.dylc@gmail.com>
To: Adrien <camaradetux@gmail.com>
Cc: Caml Mailing List <caml-list@yquem.inria.fr>
Subject: Re: [Caml-list] Optional arguments "between" non-optional ones
Date: Thu, 23 Sep 2010 16:32:20 +0200	[thread overview]
Message-ID: <AANLkTi=4gsKo=uXFwYjxwHP-Sa2rLG7rW38fMEpp1tLm@mail.gmail.com> (raw)
In-Reply-To: <AANLkTi=G6xG6b56FZsT9=n26y9f0Tzpk-3g+_P0sLo1h@mail.gmail.com>

(sorry for any double-posting)

The problem is that in your declaration of h, the inferred type for f
is of the form (unit -> unit -> ...), and you use it with the
different type (unit -> ?a:'a -> unit -> ...).

Changing ?a to be the first parameter of f change f's type to (?a:'a
-> unit -> unit -> ...). OCaml knows that it can implicitly coerce
functions when the optional parameters appear in the first position.

This is explained in the manual :
http://caml.inria.fr/pub/docs/manual-ocaml/manual006.html#htoc39

> However, in the specific case where the expected type
> is a non-labeled function type, and the argument is
> a function expecting optional parameters, the compiler
> will attempt to transform the argument to have it match
> the expected type, by passing None for all optional parameters.

A fix is to add an annotation when defining h :

let h (f : _ -> ?a:_ -> _) =
 f () ()

# let () = h f;;
bouh!
bouh!


  reply	other threads:[~2010-09-23 14:32 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-23 13:20 Adrien
2010-09-23 14:32 ` bluestorm [this message]
2010-09-23 15:05   ` Adrien
2010-09-24  1:32     ` Jacques Garrigue

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='AANLkTi=4gsKo=uXFwYjxwHP-Sa2rLG7rW38fMEpp1tLm@mail.gmail.com' \
    --to=bluestorm.dylc@gmail.com \
    --cc=camaradetux@gmail.com \
    --cc=caml-list@yquem.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).