Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
- data (a := i) j where
- type R m i j a = m (a := j) i
- returnR :: IMonad m => a -> m (a := i) i
- (!>=) :: IMonad m => m (a := j) i -> (a -> m b j) -> m b i
- fmapR :: IMonad m => (a -> b) -> m (a := j) i -> m (b := j) i
- (<!>) :: IMonad m => (a -> b) -> m (a := j) i -> m (b := j) i
- (<.>) :: IMonad m => m ((a -> b) := j) i -> m (a := k) j -> m (b := k) i
- (=<!) :: IMonad m => (a -> m b j) -> m (a := j) i -> m b i
- (!>) :: IMonad m => m (a := j) i -> m b j -> m b i
- (>!>) :: IMonad m => (a -> m (b := j) i) -> (b -> m c j) -> a -> m c i
- (<!<) :: IMonad m => (b -> m c j) -> (a -> m (b := j) i) -> a -> m c i
- joinR :: IMonad m => m (m a j := j) i -> m a i
- voidR :: IMonad m => m (a := i) i -> m (() := i) i
- foreverR :: IMonad m => m (a := i) i -> m (b := j) i
- mapMR :: IMonad m => (a -> m (b := i) i) -> [a] -> m ([b] := i) i
- mapMR_ :: IMonad m => (a -> m (b := i) i) -> [a] -> m (() := i) i
- forMR :: IMonad m => [a] -> (a -> m (b := i) i) -> m ([b] := i) i
- forMR_ :: IMonad m => [a] -> (a -> m (b := i) i) -> m (() := i) i
- replicateMR :: IMonad m => Int -> m (a := i) i -> m ([a] := i) i
- replicateMR_ :: IMonad m => Int -> m (a := i) i -> m (() := i) i
- sequenceR :: IMonad m => [m (a := i) i] -> m ([a] := i) i
- sequenceR_ :: IMonad m => [m (a := i) i] -> m (() := i) i
- whenR :: IMonad m => Bool -> m (() := i) i -> m (() := i) i
- unlessR :: IMonad m => Bool -> m (() := i) i -> m (() := i) i
- data U m a i where
- u :: Monad m => m a -> U m (a := i) i
- data D i m r = D {}
Restriction
The (:=
) type constructor restricts the index that the return value
inhabits.
returnR
and (!>=
) provide the restricted operations corresponding to
returnI
and (?>=
). If returnI
and (?>=
) satisfy the monad laws,
then so will returnR
and (!>=
):
returnR >!> f = f f >!> returnR = f (f >!> g) >!> h = f >!> (g >!> h)
The type synonym R
rearranges the type variables of the restricted monad
to match conventional notation.
data (a := i) j where Source #
(a := i)
represents a locked value of type a
that you can only access
at the index i
.
V
seals values of type a
, restricting them to a single index i
.
(!>=) :: IMonad m => m (a := j) i -> (a -> m b j) -> m b i infixl 1 Source #
A flipped bindI
that restricts the intermediate and final index.
Called "angelic bind" in Conor McBride's paper. The type of this
function has the following specialization:
(!>=) :: IMonad m => m (a := j) i -> (a -> m (b := k) j) -> m (b := k) i
Functions
fmapR :: IMonad m => (a -> b) -> m (a := j) i -> m (b := j) i Source #
All restricted monads are ordinary functors
(<.>) :: IMonad m => m ((a -> b) := j) i -> m (a := k) j -> m (b := k) i Source #
All restricted monads are restricted applicatives
(=<!) :: IMonad m => (a -> m b j) -> m (a := j) i -> m b i infixr 1 Source #
A bindI
that restricts the intermediate and final index. The type of this
function has the following specialization:
(=<!) :: IMonad m => (a -> m (b := k) j) -> m (a := j) i -> m (b := k) i
(!>) :: IMonad m => m (a := j) i -> m b j -> m b i infixl 1 Source #
Sequence two indexed monads. The type of this function has the following specialization:
(!>) :: IMonad m => m (a := j) i -> m (b := k) j -> m (b := k) i
(>!>) :: IMonad m => (a -> m (b := j) i) -> (b -> m c j) -> a -> m c i infixr 1 Source #
Composition of restricted Kleisli arrows
This is equivalent to (>>>
) from Control.Category
.
The type of this function has the following specialization:
IMonad m => (a -> m (b:= j) i) -> (b -> m (c := k) j) -> (a -> m (c := k) i)
(<!<) :: IMonad m => (b -> m c j) -> (a -> m (b := j) i) -> a -> m c i infixr 1 Source #
Composition of restricted Kleisli arrows
This is equivalent to (<<<
) from Control.Category
.
The type of this function has the following specialization:
(<!<) :: IMonad m => (b -> m (c := k) j) -> (a -> m (b := j) i) -> a -> m (c := k) i
joinR :: IMonad m => m (m a j := j) i -> m a i Source #
joinR
joins two monad layers into one. The type of this
function has the following specialization:
joinR :: IMonad m => m (m (a := k) j := j) i -> m (a := k) i
foreverR :: IMonad m => m (a := i) i -> m (b := j) i Source #
foreverR
repeats the action indefinitely
mapMR :: IMonad m => (a -> m (b := i) i) -> [a] -> m ([b] := i) i Source #
"mapMR f
" is equivalent to "sequenceR . map f
"
mapMR_ :: IMonad m => (a -> m (b := i) i) -> [a] -> m (() := i) i Source #
"mapMR_ f
" is equivalent to "sequenceR_ . map f
"
forMR :: IMonad m => [a] -> (a -> m (b := i) i) -> m ([b] := i) i Source #
mapMR
with its arguments flipped
forMR_ :: IMonad m => [a] -> (a -> m (b := i) i) -> m (() := i) i Source #
mapMR_
with its arguments flipped
replicateMR :: IMonad m => Int -> m (a := i) i -> m ([a] := i) i Source #
"replicateMR n m
" performs m
n
times and collects the results
replicateMR_ :: IMonad m => Int -> m (a := i) i -> m (() := i) i Source #
"replicateMR_ n m
" performs m
n
times and ignores the results
sequenceR :: IMonad m => [m (a := i) i] -> m ([a] := i) i Source #
Evaluate each action from left to right and collect the results
sequenceR_ :: IMonad m => [m (a := i) i] -> m (() := i) i Source #
Evaluate each action from left to right and ignore the results
whenR :: IMonad m => Bool -> m (() := i) i -> m (() := i) i Source #
"whenR p m
" executes m
if p
is True
unlessR :: IMonad m => Bool -> m (() := i) i -> m (() := i) i Source #
"unlessR p m
" executes m
if p
is False
Interoperability
The following types and functions convert between ordinary monads and restricted monads.
Use u
to convert an ordinary monad to a restricted monad so that it can be
used within an indexed do
block like so:
-- Both do blocks are indexed, using syntax rebinding from Control.IMonad.Do do x <- indexedAction lift $ do y <- u $ ordinaryAction1 x u $ ordinaryAction2 x y
Use D
to convert an index-preserving restricted monad into an ordinary
monad so that it can be used within a normal do
block.
-- An ordinary do block (i.e. without syntax rebinding from Control.IMonad.Do) do x <- D $ indexPreservingAction D $ anotherIndexPreservingAction x
The U
type 'U'pgrades ordinary monads to restricted monads