Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Data.Monad

Generic operations derived from the Applicative and Monad classes.

Like Data.Foldable, these are constrained free functions written once against the class methods (pure, ap, bind) and shared by every instance (List, Option, …). Side effects ride Prism’s effect system; this is structural sequencing over the container shape, not do-notation.

Functions and Values

join

join : forall a b. (a(a(b))) -> a(b)

Collapse one level of nesting: m(m(a)) to m(a).

map2

map2 : forall a b c d. ((a, b) -> c, d(a), d(b)) -> d(c)

Lift a binary function over two wrapped values (Applicative).

map3

map3 : forall a b c d e. ((a, b, c) -> d, e(a), e(b), e(c)) -> e(d)

Lift a ternary function over three wrapped values (Applicative).

sequence

sequence : forall a b. (List(a(b))) -> a(List(b))

Evaluate a list of wrapped values left to right, collecting the results (Applicative). Option short-circuits on None; List takes the cartesian product.

traverse_list

traverse_list : forall a b c. ((a) -> b(c), List(a)) -> b(List(c))

Apply f to each element and sequence the wrapped results (Applicative). This is sequence after a plain map.