caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Optional arguments and type annotations
@ 2001-10-31  0:05 Christian RINDERKNECHT
  2001-11-01  5:45 ` Jacques Garrigue
  0 siblings, 1 reply; 2+ messages in thread
From: Christian RINDERKNECHT @ 2001-10-31  0:05 UTC (permalink / raw)
  To: caml-list; +Cc: rinderkn

Hello List,

First, let me say I am quite new to labels (I was waiting for the 3.03
release for using them).

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.

This is not a big deal to solve:), but it looks strange to me.

Best regards,

-- 

Christian

------------------------------------------------------------------------
Christian Rinderknecht                     Phone  +82 42 866 6147
Network Architecture Laboratory            Fax    +82 42 866 6154
Information and Communications University  WWW    http://nalab.icu.ac.kr
58-4 Hwaam-dong, Yuseong-gu, Daejeon,      e-mail rinderkn@icu.ac.kr
305-732, Korea
-------------------
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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Caml-list] Optional arguments and type annotations
  2001-10-31  0:05 [Caml-list] Optional arguments and type annotations Christian RINDERKNECHT
@ 2001-11-01  5:45 ` Jacques Garrigue
  0 siblings, 0 replies; 2+ messages in thread
From: Jacques Garrigue @ 2001-11-01  5:45 UTC (permalink / raw)
  To: rinderkn; +Cc: caml-list

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2001-11-01  5:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-10-31  0:05 [Caml-list] Optional arguments and type annotations Christian RINDERKNECHT
2001-11-01  5:45 ` Jacques Garrigue

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