* RE: [Caml-list] "Or" patterns when both matchings
@ 2001-10-30 18:22 Manuel Fahndrich
2001-10-31 9:42 ` Luc Maranget
0 siblings, 1 reply; 4+ messages in thread
From: Manuel Fahndrich @ 2001-10-30 18:22 UTC (permalink / raw)
To: Luc Maranget, Pixel; +Cc: caml-list
Hmm, I must side with Pixel here. Ease of compilation is rarely a good
design principle for a programming language. The use of or patterns
allows one to factor right hand sides as in the example shown below:
| Foo(a)
| a -> <complicated expression involving a>
If Or-patterns do not follow the first-to-last matching order, then
producing correct code and reading it becomes more difficult. I wasn't
aware of the Or-compilation strategy and I'm sure I made this mistake in
the past as well.
-Maf
-----Original Message-----
From: Luc Maranget [mailto:luc.maranget@inria.fr]
Sent: Monday, October 29, 2001 2:38 AM
To: Pixel
Cc: caml-list@pauillac.inria.fr
Subject: Re: [Caml-list] "Or" patterns when both matchings
>
>
> from the documentation:
> The pattern pattern1 | pattern2 represents the logical ``or'' of the
two
> patterns pattern1 and pattern2. [...] If both matchings succeed, it
is
> undefined which set of bindings is selected.
>
> is there a reason for not using the classical pattern matching rule,
to make
> the ordering matters? (i've been nastily beat by this :-/)
>
> eg:
>
>
> type foo = Bar | Foo of foo
>
> let f1 = function
> | Foo(a)
> | a -> a
>
> let f2 = function
> | Foo(a) -> a
> | a -> a
>
> let e1 = f1 (Foo Bar) (*=> Foo Bar *)
> let e2 = f2 (Foo Bar) (*=> Bar *)
>
>
> thanks
> --
> Pixel
Yes there are two reasons
1. ease of compilation.
As you have experienced yourself. In case one of the patterns in
the or-pattern is a variable, then the or-pattern is reduced to a
variable. Otherwise, compilation would be a bit more complicated.
2. Ideology. I consider that priority in or-patterns is something
obscure, and would discourage relying on it.
However the current (unspecified) semantics makes the idea
of a ``partially useless'' matching clause a bit random, and this
semantics may become more precise in the future.
Cheers,
--Luc
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ:
http://caml.inria.fr/FAQ/
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/
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] "Or" patterns when both matchings
2001-10-30 18:22 [Caml-list] "Or" patterns when both matchings Manuel Fahndrich
@ 2001-10-31 9:42 ` Luc Maranget
0 siblings, 0 replies; 4+ messages in thread
From: Luc Maranget @ 2001-10-31 9:42 UTC (permalink / raw)
To: Manuel Fahndrich; +Cc: Luc Maranget, Pixel, caml-list
>
> Hmm, I must side with Pixel here. Ease of compilation is rarely a good
> design principle for a programming language. The use of or patterns
> allows one to factor right hand sides as in the example shown below:
>
> | Foo(a)
> | a -> <complicated expression involving a>
>
> If Or-patterns do not follow the first-to-last matching order, then
> producing correct code and reading it becomes more difficult. I wasn't
> aware of the Or-compilation strategy and I'm sure I made this mistake in
> the past as well.
>
> -Maf
>
>
You are right, I missed that point. I'll think about correcting that,
but it is not a trivial change.
Thanks for your feedback,
--Luc
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] "Or" patterns when both matchings
2001-10-28 11:02 Pixel
@ 2001-10-29 10:37 ` Luc Maranget
0 siblings, 0 replies; 4+ messages in thread
From: Luc Maranget @ 2001-10-29 10:37 UTC (permalink / raw)
To: Pixel; +Cc: caml-list
>
>
> from the documentation:
> The pattern pattern1 | pattern2 represents the logical ``or'' of the two
> patterns pattern1 and pattern2. [...] If both matchings succeed, it is
> undefined which set of bindings is selected.
>
> is there a reason for not using the classical pattern matching rule, to make
> the ordering matters? (i've been nastily beat by this :-/)
>
> eg:
>
>
> type foo = Bar | Foo of foo
>
> let f1 = function
> | Foo(a)
> | a -> a
>
> let f2 = function
> | Foo(a) -> a
> | a -> a
>
> let e1 = f1 (Foo Bar) (*=> Foo Bar *)
> let e2 = f2 (Foo Bar) (*=> Bar *)
>
>
> thanks
> --
> Pixel
Yes there are two reasons
1. ease of compilation.
As you have experienced yourself. In case one of the patterns in
the or-pattern is a variable, then the or-pattern is reduced to a
variable. Otherwise, compilation would be a bit more complicated.
2. Ideology. I consider that priority in or-patterns is something
obscure, and would discourage relying on it.
However the current (unspecified) semantics makes the idea
of a ``partially useless'' matching clause a bit random, and this
semantics may become more precise in the future.
Cheers,
--Luc
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Caml-list] "Or" patterns when both matchings
@ 2001-10-28 11:02 Pixel
2001-10-29 10:37 ` Luc Maranget
0 siblings, 1 reply; 4+ messages in thread
From: Pixel @ 2001-10-28 11:02 UTC (permalink / raw)
To: caml-list
from the documentation:
The pattern pattern1 | pattern2 represents the logical ``or'' of the two
patterns pattern1 and pattern2. [...] If both matchings succeed, it is
undefined which set of bindings is selected.
is there a reason for not using the classical pattern matching rule, to make
the ordering matters? (i've been nastily beat by this :-/)
eg:
type foo = Bar | Foo of foo
let f1 = function
| Foo(a)
| a -> a
let f2 = function
| Foo(a) -> a
| a -> a
let e1 = f1 (Foo Bar) (*=> Foo Bar *)
let e2 = f2 (Foo Bar) (*=> Bar *)
thanks
--
Pixel
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2001-10-31 9:43 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-10-30 18:22 [Caml-list] "Or" patterns when both matchings Manuel Fahndrich
2001-10-31 9:42 ` Luc Maranget
-- strict thread matches above, loose matches on Subject: below --
2001-10-28 11:02 Pixel
2001-10-29 10:37 ` Luc Maranget
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox