caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Adrien <camaradetux@gmail.com>
To: bluestorm <bluestorm.dylc@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 17:05:30 +0200	[thread overview]
Message-ID: <AANLkTimzf5ossL=eELdVk+q=Sckg0QfYaGdtK2uCR8Zr@mail.gmail.com> (raw)
In-Reply-To: <AANLkTi=4gsKo=uXFwYjxwHP-Sa2rLG7rW38fMEpp1tLm@mail.gmail.com>

On 23/09/2010, bluestorm <bluestorm.dylc@gmail.com> wrote:
> (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.

I actually expected types (?a:'a -> unit -> unit -> ...) and (unit ->
?a:'a -> unit -> ...) to work alike. I'm wondering why the arguments
are "dropped" from the first case but not the second.

Also, that's what I've done: I've simply swapped two parameters in a
function and it's working well now.

> 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.

Well spotted. I had gone a bit through the documentation but hadn't seen that.

> A fix is to add an annotation when defining h :
>
> let h (f : _ -> ?a:_ -> _) =
>  f () ()
>
> # let () = h f;;
> bouh!
> bouh!
>

I had tried to add an annotation too but (unit -> unit -> unit). Now,
thinking again about it and with your explanation, I understand better
why it had failed. I was trying to coerce f into a more restrictive
(or simply different?) type but the solution was keep the type of h's
argument broader.
Thanks.

--

Adrien Nader


  reply	other threads:[~2010-09-23 15:05 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
2010-09-23 15:05   ` Adrien [this message]
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='AANLkTimzf5ossL=eELdVk+q=Sckg0QfYaGdtK2uCR8Zr@mail.gmail.com' \
    --to=camaradetux@gmail.com \
    --cc=bluestorm.dylc@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).