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] naming parts of optional arguments?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-07-28 (16:35)
From: Chris Hecker <checker@d...>
Subject: Re: [Caml-list] naming parts of optional arguments?

>No contradiction at all: ?xy: is a label, not a variable name.

Well, except for in this case, of course, when it is a variable name:

# let f ?xy () = xy;;
val f : ?xy:'a -> unit -> 'a option = <fun>

>If you care about length, you can still write:
>   let f ?(xy=(0,0)) () = xy

No, because I need to break out the parts of the tuple and name the whole 
tuple, which was the point of the thread, so the only way to do that I can 
see is this beautiful expression:

# let f ?xy:((x,y) as xy = 0,0) () = xy,x,y;;
val f : ?xy:int * int -> unit -> (int * int) * int * int = <fun>

All I'm saying is that having the first example above work leads one to 
believe the xy is usable inside the function body in general.

On the whole, the syntax for defining default parameters is nonintuitive 
and inconsistent, because you need the parenthesis sometimes, you need the 
"as xy" sometimes, you need the ?label: sometimes, etc.


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