Browse thread
[Caml-list] Pattern matching
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Pixel <pixel@m...> |
| Subject: | Re: [Caml-list] Pattern matching |
"Diego Olivier Fernandez Pons" <FernandezPons@iFrance.com> writes: [...] > let couples = function n -> > let rec couplesCPS = function > | (n,_) -> [ ] vs > let couples = function n -> > let rec couplesCPS = function > | (i,_) when (i = n) -> [ ] the problem is an expressivity one. Something like (function A(e) -> e | _ -> ...) become dependent on the context: is there a variable "e" in the surrounding context. This is not good. One could add some sugar allowing: > let couples = function n -> > let rec couplesCPS = function > | (@@n,_) -> [ ] where @@n force the scope of n to be non-local. But too much sugar makes the language harder to learn :) [...] > let egalite = function > | (x,x) -> true > | (x,y) -> false > ;; > # This variable is bound several times in this matching i wonder why this one is not allowed since it can't have any other meaning than the one it has in prolog. What's the reason for not having it rewritten to: > let egalite = function > | (x,x') when x=x' -> true > | (x,y) -> false maybe you're right than the kind of equality (= vs ==) may be the problem... ------------------- 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