* [Caml-list] Optional and mandatory labels with the same name in the same function ?
@ 2004-07-15 11:54 Berke Durak
2004-07-15 14:11 ` Jacques GARRIGUE
0 siblings, 1 reply; 4+ messages in thread
From: Berke Durak @ 2004-07-15 11:54 UTC (permalink / raw)
To: caml-list
Has the following any use, and if not, shouldn't Ocaml better give a
warning ?
# let f ?gogo ~gogo () = 33;;
val f : ?gogo:'a -> gogo:'b -> unit -> int = <fun>
(This actually happened in some LablGtk-using code with ?packing ~packing).
--
Berke Durak
-------------------
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] Optional and mandatory labels with the same name in the same function ?
2004-07-15 11:54 [Caml-list] Optional and mandatory labels with the same name in the same function ? Berke Durak
@ 2004-07-15 14:11 ` Jacques GARRIGUE
2004-07-15 14:23 ` Richard Jones
0 siblings, 1 reply; 4+ messages in thread
From: Jacques GARRIGUE @ 2004-07-15 14:11 UTC (permalink / raw)
To: durak; +Cc: caml-list
From: Berke Durak <durak@liafa.jussieu.fr>
> Has the following any use, and if not, shouldn't Ocaml better give a
> warning ?
>
> # let f ?gogo ~gogo () = 33;;
> val f : ?gogo:'a -> gogo:'b -> unit -> int = <fun>
>
Then I suppose that
let f x x = 33
should also cause a warning, because this has just the same
semantics.
If your question was, is it possible to call such a function, then the
answer is yes:
f ~gogo:1 ~gogo:2 ()
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] Optional and mandatory labels with the same name in the same function ?
2004-07-15 14:11 ` Jacques GARRIGUE
@ 2004-07-15 14:23 ` Richard Jones
2004-07-15 14:49 ` Jacques GARRIGUE
0 siblings, 1 reply; 4+ messages in thread
From: Richard Jones @ 2004-07-15 14:23 UTC (permalink / raw)
To: Jacques GARRIGUE; +Cc: caml-list
On Thu, Jul 15, 2004 at 11:11:53PM +0900, Jacques GARRIGUE wrote:
> Then I suppose that
> let f x x = 33
> should also cause a warning, because this has just the same
> semantics.
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.
Rich.
--
Richard Jones. http://www.annexia.org/ http://www.j-london.com/
Merjis Ltd. http://www.merjis.com/ - improving website return on investment
Perl4Caml lets you use any Perl library in your type-safe Objective
CAML programs. http://www.merjis.com/developers/perl4caml/
-------------------
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] Optional and mandatory labels with the same name in the same function ?
2004-07-15 14:23 ` Richard Jones
@ 2004-07-15 14:49 ` Jacques GARRIGUE
0 siblings, 0 replies; 4+ messages in thread
From: Jacques GARRIGUE @ 2004-07-15 14:49 UTC (permalink / raw)
To: rich; +Cc: caml-list
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
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2004-07-15 14:49 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-07-15 11:54 [Caml-list] Optional and mandatory labels with the same name in the same function ? Berke Durak
2004-07-15 14:11 ` Jacques GARRIGUE
2004-07-15 14:23 ` Richard Jones
2004-07-15 14:49 ` Jacques GARRIGUE
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox