Safe Haskell | None |
---|---|
Language | Haskell98 |
A frontend module for the Control.Reference package
- data Reference wm rm s t a b = Reference (s -> rm a) (b -> s -> wm t) ((a -> wm b) -> s -> wm t)
- type Lens = Reference Identity Identity
- type Lens' w = Reference w Identity
- type Traversal = Reference Identity []
- type Traversal' w = Reference w []
- type LensPart = Reference Identity Maybe
- type LensPart' w = Reference w Maybe
- module Control.Reference.Operators
- module Control.Reference.Predefined
- module Control.Reference.TH.Monad
- module Control.Reference.TH.Generate
- module Control.Reference.TupleInstances
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
andTraversal
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.
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 Traversal = Reference Identity [] Source
The Traversal is a reference that represents an 1 to any relationship.
type Traversal' w = Reference w [] Source
type LensPart = Reference Identity Maybe Source
The parital lens is a reference that represents an 1 to 0..1 relationship.
module Control.Reference.Operators
module Control.Reference.Predefined
module Control.Reference.TH.Monad