package alba

  1. Overview
  2. Docs
include Fmlib.Module_types.MONAD
type 'a t

The type of the monad containing values of type 'a

val return : 'a -> 'a t

return a makes a monadic container containing the value a.

val (>>=) : 'a t -> ('a -> 'b t) -> 'b t

m >>= f extracts the value a from the monadic container m and returns f a.

val (>=>) : ('a -> 'b t) -> ('b -> 'c t) -> 'a -> 'c t

f >=> g composition of the two monadic functions f and g.

f >=> g is equivalent to fun a -> f a >>= g.

val map : ('a -> 'b) -> 'a t -> 'b t

map f m maps the values in the monadic container m with the function f.

val join : 'a t t -> 'a t

Remove one level of container. join m is equivalent to mm >>= fun m -> m.

val (<*>) : ('a -> 'b) t -> 'a t -> 'b t

f <*> m applies the function contained in f to the content of the monadic container m and injects the result into a new monadic container.

module Path : sig ... end
module Process : sig ... end
module Directory : sig ... end
module File : sig ... end
module Stdout : sig ... end

Write to standard output (usually the screen).

module Stderr : sig ... end

Write to standard error (usually the screen).

val cli_loop : 'a -> ('a -> string option) -> ('a -> string -> 'a t) -> ('a -> 'a t) -> 'a t

cli_loop state prompt next stop runs a cli loop which starts in state state and prompts its users with the string returned by prompt state. If prompt state returns None, the cli_loop is ended.

If the user enters a line, the command next state line is performed.

If prompt state returns None or the user ends its input by pressing ctrl-d, the command stop state is performed.


The following command starts a cli_loop and prompts the user at most 5 times with i> and echoes back the input of the user.

    (fun i ->
        if i < 5 then
            Some (string_of_int i ^ "> ")
    (fun i line ->
        Stdout.line line >>= fun _ -> return (i + 1))
    (fun _ -> return ())