Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Optional arguments in inherited methods
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-04-29 (08:48)
From: Jacques GARRIGUE <garrigue@k...>
Subject: Re: [Caml-list] Optional arguments in inherited methods
From: Henri DF <>

> > Unfortunate, but in the case of optional arguments the problem is
> > not with typing but with how they are implemented: an optional
> > argument of type [t] is actually a non-optional argument of type [t
> > option]. They disappear automagically on application, but this means
> > that None's are automatically inserted. So applying a function which has
> > optional arguments is completely different from a function without
> > them (even if the function call looks the same in your source code).
> what about optional arguments which have a default value? i would assume 
> these are not implemented using options, so would that change anything 
> here?

They are also implemented with options.

  let f ?(x=0) y = x + y

is just a shorthand for

  let f ?x y = let x = match x with Some x -> x | None -> 0 in x + y

(I believe this is explained in the manual)

Why is it this way? Just because the ocaml type system is such that we
don't want to have values inside types, which is the approach you can
see in C++ for instance.

Jacques Garrigue

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: