Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Optional and mandatory labels with the same name in the same function ?
[ 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 and mandatory labels with the same name in the same function ?
From: Richard Jones <rich@annexia.org>

> It's a bit more subtle than that.  OCaml 3.07 always picks the last
> argument, and ignores the others.  Thus:
> 
> # let f x x = x;;
> val f : 'a -> 'b -> 'b = <fun>
> # let f x x x x = x;;
> val f : 'a -> 'b -> 'c -> 'd -> 'd = <fun>
> 
> But a future version might pick the first argument, or one in the
> middle, or one at random.  I can't find any guarantee in the manual
> that the behaviour won't change, so this might cause a bug.

Well, it's not directly related to the question I was answering, but I
can reassure you. This behaviour is well defined, because
  let f x x = x
is no more than a shorthand for
  let f = fun x -> fun x -> x
which is quite natural for anybody versed in lambda-calculus.
I cannot cite you whre the manual specifies that, but this not a case
of undefined behaviour.

More generally, ocaml may leave some runtime behaviour unspecified,
but the static behaviour (type-checking) is expected to be fully
specified.

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