English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

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.

Chris

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