Module Exception


module Exception: sig .. end
Exception is a purely functional replacement of OCaml's built-in exceptions.

To indicate a normal value use Exception.return. For exceptional conditions use Exception.throw. Function Exception.catch splices in an exception handler into the thread of control. Execute an exception monad with Exception.run.


type ('a, 'b) t 
Type of an exception monad. 'left is the exception's type and 'right is the normal value's type.
val bind : ('a, 'b) t -> ('b -> ('a, 'c) t) -> ('a, 'c) t
bind a_monad a_function

Apply a_function to a_monad producing another monad. a_function takes a normal value as argument and returns a monad.

val return : 'a -> ('b, 'a) t
return a_normal_value

Answer a_normal_value.

val throw : 'a -> ('a, 'b) t
throw an_exception

Answer an_exception, or in other words, throw an_exception.

val catch : ('a, 'b) t -> ('a -> ('c, 'b) t) -> ('c, 'b) t
catch a_monad an_exception_handler

Catch exceptions from a_monad and feed them into an_exception_handler. an_exception_handler takes an exceptional value as argument and returns a monad.

val run : ('a -> 'b) -> ('c -> 'b) -> ('a, 'c) t -> 'b
run a_failure_function a_success_function a_monad

Run a_monad. If a_monad does not Exception.throw an exception, pass the result of evaluating the monad to a_success_function. Otherwise, if the a_monad throws, pass the exception to a_failure_function.