Safe Haskell | None |
---|---|
Language | Haskell98 |
Common operators for references. References bind the types of the read and write monads of a reference.
The naming of the operators follows the given convetions:
- There are four kinds of operator for every type of reference.
The operators are either getters (
^_
), setters (_=
), monadic updaters (_~
), pure updaters (_-
) or action performers (_|
). The_
will be replaced with the signs of the monads accessable. - There are pure operators for
Lens
(.
), partial operators forPartial
lenses (?
), operators forTraversal
(*
), and operators that work insideIO
forIOLens
(!
). - Different reference types can be combined, the outermost monad is the first character.
Example: Partial IO lens (
?!
). But partial lens and traversal combined is simply a traversal. - Generic operators (
#
) do not bind the types of the monads, so they must disambiguated manually.
- turn :: Reference w r w' r' s t a b -> Reference w' r' w r a b s t
- review :: Reference MU MU Identity Identity s t a b -> a -> s
- (^#) :: RefMonads w r => s -> Reference w r w' r' s t a b -> r a
- (^.) :: s -> Lens' s t a b -> a
- (^?) :: s -> Partial' s t a b -> Maybe a
- (^*) :: s -> Traversal' s t a b -> [a]
- (^!) :: s -> IOLens' s t a b -> IO a
- (^?!) :: s -> IOPartial' s t a b -> IO (Maybe a)
- (^*!) :: s -> IOTraversal' s t a b -> IO [a]
- (#=) :: Reference w r w' r' s t a b -> b -> s -> w t
- (.=) :: Lens' s t a b -> b -> s -> t
- (?=) :: Partial' s t a b -> b -> s -> t
- (*=) :: Traversal' s t a b -> b -> s -> t
- (!=) :: IOLens' s t a b -> b -> s -> IO t
- (?!=) :: IOPartial' s t a b -> b -> s -> IO t
- (*!=) :: IOTraversal' s t a b -> b -> s -> IO t
- (#~) :: Reference w r w' r' s t a b -> (a -> w b) -> s -> w t
- (.~) :: Lens' s t a b -> (a -> Identity b) -> s -> t
- (?~) :: Partial' s t a b -> (a -> Identity b) -> s -> t
- (*~) :: Traversal' s t a b -> (a -> Identity b) -> s -> t
- (!~) :: IOLens' s t a b -> (a -> IO b) -> s -> IO t
- (?!~) :: IOPartial' s t a b -> (a -> IO b) -> s -> IO t
- (*!~) :: IOTraversal' s t a b -> (a -> IO b) -> s -> IO t
- (#-) :: Monad w => Reference w r w' r' s t a b -> (a -> b) -> s -> w t
- (.-) :: Lens' s t a b -> (a -> b) -> s -> t
- (?-) :: Partial' s t a b -> (a -> b) -> s -> t
- (*-) :: Traversal' s t a b -> (a -> b) -> s -> t
- (!-) :: IOLens' s t a b -> (a -> b) -> s -> IO t
- (?!-) :: IOPartial' s t a b -> (a -> b) -> s -> IO t
- (*!-) :: IOTraversal' s t a b -> (a -> b) -> s -> IO t
- (#|) :: Monad w => Reference w r w' r' s s a a -> (a -> w x) -> s -> w s
- (!|) :: IOLens' s s a a -> (a -> IO c) -> s -> IO s
- (?!|) :: IOPartial' s s a a -> (a -> IO c) -> s -> IO s
- (*!|) :: IOTraversal' s s a a -> (a -> IO c) -> s -> IO s
- (&) :: (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
- (&+&) :: (RefMonads w r, RefMonads w' r', MonadPlus r, MonadPlus r', MMorph [] 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
- (&|&) :: 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')
Documentation
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
Getters
(^#) :: RefMonads w r => s -> Reference w r w' r' s t a b -> r a infixl 4 Source
Gets the referenced data in the monad of the lens. Does not bind the type of the writer monad, so the reference must have its type disambiguated.
(^*) :: s -> Traversal' s t a b -> [a] infixl 4 Source
Traversal version of ^#
(^*!) :: s -> IOTraversal' s t a b -> IO [a] infixl 4 Source
IO traversal version of ^#
Setters
(#=) :: Reference w r w' r' s t a b -> b -> s -> w t infixl 4 Source
Sets the referenced data to the given pure value in the monad of the reference.
Does not bind the type of the reader monad, so the reference must have its type disambiguated.
(*=) :: Traversal' s t a b -> b -> s -> t infixl 4 Source
Traversal version of '#='
(?!=) :: IOPartial' s t a b -> b -> s -> IO t infixl 4 Source
Partial IO version of '#='
(*!=) :: IOTraversal' s t a b -> b -> s -> IO t infixl 4 Source
Traversal IO version of '#='
Updaters
(#~) :: Reference w r w' r' s t a b -> (a -> w b) -> s -> w t infixl 4 Source
Applies the given monadic function on the referenced data in the monad of the lens.
Does not bind the type of the reader monad, so the reference must have its type disambiguated.
(*~) :: Traversal' s t a b -> (a -> Identity b) -> s -> t infixl 4 Source
Traversal version of '#~'
(?!~) :: IOPartial' s t a b -> (a -> IO b) -> s -> IO t infixl 4 Source
Partial IO version of '#~'
(*!~) :: IOTraversal' s t a b -> (a -> IO b) -> s -> IO t infixl 4 Source
Traversal IO version of '#~'
Updaters with pure function inside
(#-) :: Monad w => Reference w r w' r' s t a b -> (a -> b) -> s -> w t infixl 4 Source
Applies the given pure function on the referenced data in the monad of the lens.
Does not bind the type of the reader monad, so the reference must have its type disambiguated.
(*-) :: Traversal' s t a b -> (a -> b) -> s -> t infixl 4 Source
Traversal version of '#-'
(?!-) :: IOPartial' s t a b -> (a -> b) -> s -> IO t infixl 4 Source
Partial IO version of '#-'
(*!-) :: IOTraversal' s t a b -> (a -> b) -> s -> IO t infixl 4 Source
Traversal IO version of '#-'
Updaters with only side-effects
(#|) :: Monad w => Reference w r w' r' s s a a -> (a -> w x) -> s -> w s infixl 4 Source
Performs the given monadic action on referenced data while giving back the original data.
Does not bind the type of the reader monad, so the reference must have its type disambiguated.
(?!|) :: IOPartial' s s a a -> (a -> IO c) -> s -> IO s infixl 4 Source
Partial IO version of '#|'
(*!|) :: IOTraversal' s s a a -> (a -> IO c) -> s -> IO s infixl 4 Source
Traversal IO version of '#|'
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', MMorph [] 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
Adds two references.
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.