references-0.3.3.1: Selectors for reading and updating data.

Control.Reference.Combinators

Contents

Description

Operators to combine and transform references.

Synopsis

Binary operators on references

(&) :: (Monad w, Monad r) => Reference w r w' r' s t c d -> Reference w r w' r' c d a b -> Reference w r w' r' s t a b infixl 6 Source #

Composes two references. They must be of the same kind.

If reference r accesses b inside the context a, and reference p accesses c inside the context b, than the reference r&p will access c inside a.

Composition is associative: (r&p)&q = r&(p&q)

(&+&) :: (RefMonads w r, RefMonads w' r', MonadPlus r, MonadPlus r', Morph [] r) => Reference w r w' r' s s a a -> Reference w r w' r' s s a a -> Reference w r w' r' s s a a infixl 5 Source #

Using this operator may result in accessing the same parts of data multiple times. For example twice = self &+& self is a reference that accesses itself twice:

a ^? twice == [a,a]
(twice *= x) a == x
(twice .- f) a == f (f a)

Addition is commutative only if we do not consider the order of the results from a get, or the order in which monadic actions are performed.

(&|&) :: RefMonads m m' => Reference m m m' m' s t a b -> Reference m m m' m' s' t' a' b' -> Reference m m m' m' (s, s') (t, t') (a, a') (b, b') infixl 5 Source #

Pack two references in parallel.

turn :: Reference w r w' r' s t a b -> Reference w' r' w r a b s t Source #

Flips a reference to the other direction. The monads of the references can change when a reference is turned.