Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
From: Jacques Garrigue <garrigue@k...>
Subject: Re: [Caml-list] naming parts of optional arguments?
From: Chris Hecker <checker@d6.com>
Date: Sun, 27 Jul 2003 20:41:57 -0700

> [old thread resurrected]

Very old indeed.

> Actually, I spoke too soon below, you have to have the "as xy" on there to 
> be able to reference the tuple by xy.  Doesn't that seem redundant given 
> the ?xy: specification (which doesn't seem to be used)?
> 
> # let f ?xy:((x,y)=(0,0)) () = x + y;;
> val f : ?xy:int * int -> unit -> int = <fun>
> # let f ?xy:((x,y)=(0,0)) () = xy;;
> Characters 29-31:
>    let f ?xy:((x,y)=(0,0)) () = xy;;
>                                 ^^
> Unbound value xy
> # let f ?xy:((x,y) as xy =(0,0)) () = xy;;
> val f : ?xy:int * int -> unit -> int * int = <fun>
> # let f ?xy:((x,y) as blah =(0,0)) () = blah;;
> val f : ?xy:int * int -> unit -> int * int = <fun>

No contradiction at all: ?xy: is a label, not a variable name.
If you care about length, you can still write:

  let f ?(xy=(0,0)) () = xy

The distinction between label and variable is useful to avoid masking
the environment.

  let x = ref 3
  let f ?x:(x' = !x + 1) () = x := x'

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