This module provides a simple abstract data type for a piece of a data stucture that can be read from and written to. In contrast to Data.Accessor.Basic it is intended for unqualified import.
- type Accessor s a = T s a
- accessor :: (s -> a) -> (a -> s -> s) -> Accessor s a
- setVal :: Accessor s a -> a -> s -> s
- getVal :: Accessor s a -> s -> a
- getA :: MonadState s m => Accessor s a -> m a
- putA :: MonadState s m => Accessor s a -> a -> m ()
- (=:) :: MonadState s m => Accessor s a -> a -> m ()
- modA :: MonadState s m => Accessor s a -> (a -> a) -> m ()
- (.>) :: Accessor a b -> Accessor b c -> Accessor a c
- (<.) :: Accessor b c -> Accessor a b -> Accessor a c
Documentation
type Accessor s a = T s aSource
An Accessor s a
is an object that encodes how to
get and put a subject of type a
out of/into an object
of type s
.
In order for an instance of this data structure a
to be
an Accessor
, it must obey the following laws:
getVal a (setVal a x s) = x setVal a (getVal a s) s = s
:: (s -> a) | get method |
-> (a -> s -> s) | set method |
-> Accessor s a |
Construct an Accessor
from a get
and a set
method.
:: Accessor s a | record field |
-> a | value |
-> s | original record |
-> s | new record with field |
Set a value of a record field that is specified by an Accessor
:: Accessor s a | record field |
-> s | record |
-> a | value of the field in the record |
Get a value from a record field that is specified by an Accessor
getA :: MonadState s m => Accessor s a -> m aSource
A structural dereference function for state monads.
putA :: MonadState s m => Accessor s a -> a -> m ()Source
A structural assignment function for state monads.
(=:) :: MonadState s m => Accessor s a -> a -> m ()Source
An "assignment operator" for state monads.
(=:) = putA
modA :: MonadState s m => Accessor s a -> (a -> a) -> m ()Source
A structural modification function for state monads.