Duppy.MonadMonadic interface to Duppy.Io. * * This module can be used to write code * that runs in various Duppy's tasks and * raise values in a completely transparent way. * * You can see examples of its use * in the examples/ directory of the * source code and in the files * src/tools/{harbor.camlp4,server.camlp4} * in liquidsoap's code. * * When a server communicates * with a client, it performs several * computations and, eventually, terminates. * A computation can either return a new * value or terminate. For instance: * * - Client connects. * - Server tries to authenticate the client. * - If authentication is ok, proceed with the next step. * - Otherwise terminate. * * The purpose of the monad is to embed * computations which can either return * a new value or raise a value that is used * to terminate.
Type representing a computation * which returns a value of type 'a * or raises a value of type 'b
val return : 'a -> ('a, 'b) treturn x create a computation that * returns value x.
val raise : 'b -> ('a, 'b) traise x create a computation that raises * value x.
Compose two computations. * bind f g is equivalent to: * let x = f in g x where x * has f's return type.
val run : return:('a -> unit) -> raise:('b -> unit) -> ('a, 'b) t -> unitrun f ~return ~raise () executes f and process * returned values with return or raised values * with raise.
catch f g redirects values x raised during * f's execution to g. The name suggests the * usual try .. with .. exception catching.
fold_left f a [b1; b2; ..] returns computation * (f a b1) >>= (fun a -> f a b2) >>= ...
iter f [x1; x2; ..] returns computation * f x1 >>= (fun () -> f x2) >>= ...
module Mutex : sig ... endThis module implements monadic * mutex computations. They can be used * to write blocking code that is compatible * with duppy's tasks, i.e. Mutex.lock m blocks * the calling computation and not the calling thread.
module Condition : sig ... endThis module implements monadic * condition computations. They can be used * to write waiting code that is compatible * with duppy's tasks, i.e. Condition.wait c m blocks * the calling computation and not the calling thread * until Condition.signal c or Condition.broadcast c has * been called.
module type Monad_io_t = sig ... endThis module implements monadic computations * using Duppy.Io. It can be used to create * computations that read or write from a socket, * and also to redirect a computation in a different * queue with a new priority.
module Io : Monad_io_t with type socket = Unix.file_descr and module Io = Io