references-0.1.0.0: Generalization of lenses, folds and traversals for haskell

Safe HaskellNone
LanguageHaskell98

Control.Reference

Description

A frontend module for the Control.Reference package

Synopsis

Documentation

data Reference wm rm s t a b Source

A reference is an accessor to a part or different view of some data. The reference, unlike the lens has a separate getter, setter and updater.

Reference laws

As the references are generalizations of lenses, they should conform to the lens laws:

1) You get back what you put in:

lensSet l a s >>= lensGet l ≡ a

2) Putting back what you got doesn't change anything:

lensGet l a >>= b -> lensSet l b s ≡ s

3) Setting twice is the same as setting once:

lensSet l a s >>= lensSet l b ≡ lensSet l b s

But because they are more powerful than lenses, they should be more responsible.

4) Updating something is the same as getting and then setting:

lensGet l a >>= f >>= b -> lensSet l b s ≡ lensUpdate b s

Type arguments

wm
Writer monad, controls how the value can be reassembled when the part is changed. Usually Identity.
rm
Reader monad. Controls how part of the value can be accessed. See Lens, LensPart and Traversal
s
The original context.
t
The context after replacing the accessed part to something of type b.
a
The accessed part.
b
The accessed part can be changed to this.

Constructors

Reference (s -> rm a) (b -> s -> wm t) ((a -> wm b) -> s -> wm t) 

type Lens = Reference Identity Identity Source

The Lens is a reference that represents an 1 to 1 relationship.

type Lens' w = Reference w Identity Source

type Traversal = Reference Identity [] Source

The Traversal is a reference that represents an 1 to any relationship.

type LensPart = Reference Identity Maybe Source

The parital lens is a reference that represents an 1 to 0..1 relationship.