caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@kurims.kyoto-u.ac.jp>
To: rinderkn@hugo.int-evry.fr
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Optional arguments and type annotations
Date: Thu, 01 Nov 2001 14:45:30 +0900	[thread overview]
Message-ID: <20011101144530J.garrigue@kurims.kyoto-u.ac.jp> (raw)
In-Reply-To: <20011031010534.A26259@hugo.int-evry.fr>

From: Christian RINDERKNECHT <rinderkn@hugo.int-evry.fr>

> I am used to annotate the top-level functions with their types, and I
> was surprised to see that I must write the following to make it
> type-check: 
> 
> #let bump ?(step:int option) (x:int) =
>    match step with
>      None -> x * 2
>    | Some y -> x + y
>  ;;
> val bump : ?step:int -> int -> int = <fun>
> 
> and then there is a discrepancy between the "int option" annotation in
> the .ml and the "int" in the interface.

As you can see with the pattern matching, from inside the function
step is of type "int option". But since it is optional, when applying
the function you can simply pass an argument of type "int", which is
reflected by the external type of the function.

This is not to say that there is no discrepancy: actually, if you pass
an argument with label ?step: instead of ~step:, it has to be of type
"int option", so that we could have written "?step:int option -> int
-> int". But since an optional argument must always have type "t
option", the "option" part is redondant, and omitted in the
printed and parsed types (it actually appears inside the type checker).

Hope this is not too misleading.

Jacques Garrigue
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


      reply	other threads:[~2001-11-01  5:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-10-31  0:05 Christian RINDERKNECHT
2001-11-01  5:45 ` Jacques Garrigue [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=20011101144530J.garrigue@kurims.kyoto-u.ac.jp \
    --to=garrigue@kurims.kyoto-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=rinderkn@hugo.int-evry.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).