Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
From: Jacques GARRIGUE <garrigue@k...>
Subject: Re: [Caml-list] Optional arguments in inherited methods
From: Henri DF <henri.dubois-ferriere@epfl.ch>

> > 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 caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners