Copyright | [2018..2020] The Accelerate Team |
---|---|
License | BSD3 |
Maintainer | Trevor L. McDonell <trevor.mcdonell@gmail.com> |
Stability | experimental |
Portability | non-portable (GHC extensions) |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Synopsis
- class Functor m => Monad m where
- (=<<) :: (Monad m, Elt a, Elt b, Elt (m a), Elt (m b)) => (Exp a -> Exp (m b)) -> Exp (m a) -> Exp (m b)
- (>>) :: (Monad m, Elt a, Elt b, Elt (m a), Elt (m b)) => Exp (m a) -> Exp (m b) -> Exp (m b)
- (>=>) :: (Monad m, Elt a, Elt b, Elt c, Elt (m b), Elt (m c)) => (Exp a -> Exp (m b)) -> (Exp b -> Exp (m c)) -> Exp a -> Exp (m c)
- (<=<) :: (Monad m, Elt a, Elt b, Elt c, Elt (m b), Elt (m c)) => (Exp b -> Exp (m c)) -> (Exp a -> Exp (m b)) -> Exp a -> Exp (m c)
- when :: (Monad m, Elt (m ())) => Exp Bool -> Exp (m ()) -> Exp (m ())
- unless :: (Monad m, Elt (m ())) => Exp Bool -> Exp (m ()) -> Exp (m ())
- liftM :: (Monad m, Elt a, Elt b, Elt (m a), Elt (m b)) => (Exp a -> Exp b) -> Exp (m a) -> Exp (m b)
- liftM2 :: (Monad m, Elt a, Elt b, Elt c, Elt (m a), Elt (m b), Elt (m c)) => (Exp a -> Exp b -> Exp c) -> Exp (m a) -> Exp (m b) -> Exp (m c)
- liftM3 :: (Monad m, Elt a, Elt b, Elt c, Elt d, Elt (m a), Elt (m b), Elt (m c), Elt (m d)) => (Exp a -> Exp b -> Exp c -> Exp d) -> Exp (m a) -> Exp (m b) -> Exp (m c) -> Exp (m d)
- liftM4 :: (Monad m, Elt a, Elt b, Elt c, Elt d, Elt e, Elt (m a), Elt (m b), Elt (m c), Elt (m d), Elt (m e)) => (Exp a -> Exp b -> Exp c -> Exp d -> Exp e) -> Exp (m a) -> Exp (m b) -> Exp (m c) -> Exp (m d) -> Exp (m e)
- liftM5 :: (Monad m, Elt a, Elt b, Elt c, Elt d, Elt e, Elt f, Elt (m a), Elt (m b), Elt (m c), Elt (m d), Elt (m e), Elt (m f)) => (Exp a -> Exp b -> Exp c -> Exp d -> Exp e -> Exp f) -> Exp (m a) -> Exp (m b) -> Exp (m c) -> Exp (m d) -> Exp (m e) -> Exp (m f)
Monad class
class Functor m => Monad m where Source #
The Monad
class is used for scalar types which can be sequenced.
Instances of Monad
should satisfy the following laws:
- Left identity
return
a>>=
k = k a- Right identity
m
>>=
return
= m- Associativity
m
>>=
(\x -> k x>>=
h) = (m>>=
k)>>=
h
Furthermore, the Monad
and Functor
operations should relate as follows:
* fmap
f xs = xs >>=
return
. f
(>>=) :: (Elt a, Elt b, Elt (m a), Elt (m b)) => Exp (m a) -> (Exp a -> Exp (m b)) -> Exp (m b) infixl 1 Source #
Sequentially compose two actions, passing any value produced by the first as an argument to the second.
'as
' can be understood as the >>=
bsdo
expression
do a <- as bs a
return :: (Elt a, Elt (m a)) => Exp a -> Exp (m a) Source #
Inject a value into the monadic type
Functions
Basic functions
(=<<) :: (Monad m, Elt a, Elt b, Elt (m a), Elt (m b)) => (Exp a -> Exp (m b)) -> Exp (m a) -> Exp (m b) infixr 1 Source #
Same as >>=
, but with the arguments interchanged
(>>) :: (Monad m, Elt a, Elt b, Elt (m a), Elt (m b)) => Exp (m a) -> Exp (m b) -> Exp (m b) infixl 1 Source #
Sequentially compose two actions, discarding any value produced by the first, like sequencing operators (such as the semicolon) in imperative languages.
'as
' can be understood as the >>
bsdo
expression
do as bs
(>=>) :: (Monad m, Elt a, Elt b, Elt c, Elt (m b), Elt (m c)) => (Exp a -> Exp (m b)) -> (Exp b -> Exp (m c)) -> Exp a -> Exp (m c) infixr 1 Source #
Left-to-right composition of Kleisli arrows.
'(bs
' can be understood as the >=>
cs) ado
expression
do b <- bs a cs b
(<=<) :: (Monad m, Elt a, Elt b, Elt c, Elt (m b), Elt (m c)) => (Exp b -> Exp (m c)) -> (Exp a -> Exp (m b)) -> Exp a -> Exp (m c) infixr 1 Source #
Right-to-left composition of Kleisli arrows. (
, with the arguments
flipped.>=>
)
Note how this operator resembles function composition (
:.
)
(.) :: (b -> c) -> (a -> b) -> a -> c (<=<) :: Monad m => (b -> m c) -> (a -> m b) -> a -> m c
Conditional execution of monadic expressions
when :: (Monad m, Elt (m ())) => Exp Bool -> Exp (m ()) -> Exp (m ()) Source #
Conditional execution of a monadic expression
Monadic lifting operations
liftM :: (Monad m, Elt a, Elt b, Elt (m a), Elt (m b)) => (Exp a -> Exp b) -> Exp (m a) -> Exp (m b) Source #
Promote a function to a monad
liftM2 :: (Monad m, Elt a, Elt b, Elt c, Elt (m a), Elt (m b), Elt (m c)) => (Exp a -> Exp b -> Exp c) -> Exp (m a) -> Exp (m b) -> Exp (m c) Source #
Promote a function to a monad, scanning the monadic arguments from left to right.
liftM3 :: (Monad m, Elt a, Elt b, Elt c, Elt d, Elt (m a), Elt (m b), Elt (m c), Elt (m d)) => (Exp a -> Exp b -> Exp c -> Exp d) -> Exp (m a) -> Exp (m b) -> Exp (m c) -> Exp (m d) Source #
Promote a function to a monad, scanning the monadic arguments from
left to right (cf. liftM2
)
liftM4 :: (Monad m, Elt a, Elt b, Elt c, Elt d, Elt e, Elt (m a), Elt (m b), Elt (m c), Elt (m d), Elt (m e)) => (Exp a -> Exp b -> Exp c -> Exp d -> Exp e) -> Exp (m a) -> Exp (m b) -> Exp (m c) -> Exp (m d) -> Exp (m e) Source #
Promote a function to a monad, scanning the monadic arguments from
left to right (cf. liftM2
)
liftM5 :: (Monad m, Elt a, Elt b, Elt c, Elt d, Elt e, Elt f, Elt (m a), Elt (m b), Elt (m c), Elt (m d), Elt (m e), Elt (m f)) => (Exp a -> Exp b -> Exp c -> Exp d -> Exp e -> Exp f) -> Exp (m a) -> Exp (m b) -> Exp (m c) -> Exp (m d) -> Exp (m e) -> Exp (m f) Source #
Promote a function to a monad, scanning the monadic arguments from
left to right (cf. liftM2
)