package duppy
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Module Duppy.MonadSource
Monadic 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
Compose two computations. * bind f g is equivalent to: * let x = f in g x where x * has f's return type.
>>= is an alternative notation * for bind
run 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.
=<< is an alternative notation for catch.
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) >>= ...
This 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.
This 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.
This 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.