This behavior is expected given than OCaml is strict, and your
operator <|||> would be an ordinary function (unlike || and
&&). You have to use either functions (or lazy values)
instead of expressions, or options instead of exceptions.
Tiphaine
Le 17/02/2012 19:16, Pierre-Alexandre Voye a écrit :
Hello, I'm trying to implement a scala concept
"partial application" in which one can chains pattern matching
function. If the first failed, the second is tried.
It seems it is impossible to give an exception as argument to a
function.
exception Nothing;;
let (<|||>) a b = try a
with
| Nothing -> (try b
with
| Nothing -> raise
Nothing);;
val ( <|||> ) : 'a -> 'a -> 'a = <fun>
(raise Nothing) <|||>
"jj";;
Exception: Nothing.
But if I try :
try (raise Nothing)
with
| Nothing -> (try
"jj"with
| Nothing -> raise
Nothing);;
- : string = "jj"
Is there a workaround ?
Regards,
P-A
--
---------------------
https://twitter.com/#!/ontologiae/
http://linuxfr.org/users/montaigne