[Caml-list] How an exception could be an argument

2012-02-17 Thread Pierre-Alexandre Voye
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

Re: [Caml-list] How an exception could be an argument

2012-02-17 Thread Tiphaine Turpin
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 :

Re: [Caml-list] How an exception could be an argument

2012-02-17 Thread Edgar Friendly
Here is an example of giving an exception as an argument to a function: let run_or ~cmd ~err = if Sys.command cmd 0 then raise err and an example usage: let config_fail = Failure (Could not configure ^ p.id) in run_or ~cmd:(sh configure ^ config_opt) ~err:config_fail; The problem with your

Re: [Caml-list] How an exception could be an argument

2012-02-17 Thread Vincent Aravantinos
The arguments are evaluated before being passed to the function. So in your first test, Nothing is raised before even entering |||. In the second case you're circumventing this by copying directly raise Nothing in the body of the function: this copy-pasting is not equivalent since you now force