|
|
|
Description |
This module defines the Accessor type.
It should be imported with qualification.
|
|
Synopsis |
|
|
|
Documentation |
|
|
The access functions we propose, look very similar to those
needed for List.mapAccumL (but parameter order is swapped) and State monad.
They get the new value of the field and the record
and return the old value of the field and the record with the updated field.
| Instances | |
|
|
fromSetGet :: (a -> r -> r) -> (r -> a) -> T r a | Source |
|
|
fromLens :: (r -> (a, a -> r)) -> T r a | Source |
|
|
fromWrapper :: (b -> a) -> (a -> b) -> T a b | Source |
|
If an object is wrapped in a newtype,
you can generate an Accessor to the unwrapped data
by providing a wrapper and an unwrapper function.
The set function is simpler in this case,
since no existing data must be kept.
Since the information content of the wrapped and unwrapped data is equivalent,
you can swap wrapper and unwrapper.
This way you can construct an Accessor
that treats a record field containing an unwrapped object
like a field containing a wrapped object.
newtype A = A {unA :: Int}
access :: Accessor.T A Int
access = fromWrapper A unA
|
|
|
Access the record itself
|
|
|
Access a (non-existing) element of type ()
|
|
|
result a accesses the value of a function for argument a.
Also see semantic editor combinators,
that allow to modify all function values of a function at once.
Cf. http://conal.net/blog/posts/semantic-editor-combinators/
|
|
|
Set the value of a field.
|
|
|
set as infix operator.
This lets us write first ^= 2+3 $ second ^= 5+7 $ record.
|
|
compose :: [r -> r] -> r -> r | Source |
|
This is a general function,
but it is especially useful for setting many values of different type at once.
|
|
|
Get the value of a field.
|
|
|
get as infix operator.
This lets us write record^.field^.subfield.
This imitates Modula II syntax.
|
|
modify :: T r a -> (a -> a) -> r -> r | Source |
|
Transform the value of a field by a function.
|
|
(^:) :: T r a -> (a -> a) -> r -> r | Source |
|
modify as infix operator.
This lets us write
field^:subfield^:(2*) $ record,
record$%field^:subfield^:(2*)
or record$%field^:subfield^:(const 1).
|
|
|
Accessor composition:
Combine an accessor with an accessor to a sub-field.
Speak "stack".
|
|
|
Accessor composition the other direction.
(<.) = flip (.>)
|
|
($%) :: a -> (a -> b) -> b | Source |
|
Flipped version of '($)'.
|
|
Produced by Haddock version 2.4.2 |