Safe Haskell | None |
---|---|
Language | Haskell98 |
- (==<<) :: Monad m => (a -> b -> m c) -> (m a, m b) -> m c
- when_ :: Monad m => Bool -> m a -> m ()
- unless_ :: Monad m => Bool -> m a -> m ()
- whenM :: Monad m => m Bool -> m a -> m ()
- unlessM :: Monad m => m Bool -> m a -> m ()
- ifM :: Monad m => m Bool -> m a -> m a -> m a
- ifNotM :: Monad m => m Bool -> m a -> m a -> m a
- and2M :: Monad m => m Bool -> m Bool -> m Bool
- andM :: Monad m => [m Bool] -> m Bool
- or2M :: Monad m => m Bool -> m Bool -> m Bool
- orM :: Monad m => [m Bool] -> m Bool
- altM1 :: Monad m => (a -> m (Either err b)) -> [a] -> m (Either err b)
- mapM' :: (Foldable t, Monad m, Monoid b) => (a -> m b) -> t a -> m b
- forM' :: (Foldable t, Monad m, Monoid b) => t a -> (a -> m b) -> m b
- type Cont r a = (a -> r) -> r
- thread :: (a -> Cont r b) -> [a] -> Cont r [b]
- zipWithM' :: Monad m => (a -> b -> m c) -> [a] -> [b] -> m [c]
- mapMaybeM :: (Monad m, Functor m) => (a -> m (Maybe b)) -> [a] -> m [b]
- forMaybeM :: (Monad m, Functor m) => [a] -> (a -> m (Maybe b)) -> m [b]
- dropWhileM :: Monad m => (a -> m Bool) -> [a] -> m [a]
- finally :: (Error e, MonadError e m) => m a -> m b -> m a
- bracket_ :: Monad m => m a -> (a -> m c) -> m b -> m b
- localState :: MonadState s m => m a -> m a
- readM :: (Error e, MonadError e m, Read a) => String -> m a
- when :: Applicative f => Bool -> f () -> f ()
- unless :: Applicative f => Bool -> f () -> f ()
- class (Alternative m, Monad m) => MonadPlus m where
- (<$>) :: Functor f => (a -> b) -> f a -> f b
- (<*>) :: Applicative f => forall a b. f (a -> b) -> f a -> f b
- (<$) :: Functor f => forall a b. a -> f b -> f a
- modify' :: MonadState s m => (s -> s) -> m ()
Documentation
when_ :: Monad m => Bool -> m a -> m () Source
when_
is just Control.Monad.when
with a more general type.
unless_ :: Monad m => Bool -> m a -> m () Source
unless_
is just Control.Monad.unless
with a more general type.
altM1 :: Monad m => (a -> m (Either err b)) -> [a] -> m (Either err b) Source
Lazy monadic disjunction with Either
truth values.
mapM' :: (Foldable t, Monad m, Monoid b) => (a -> m b) -> t a -> m b Source
Generalized version of mapM_ :: Monad m => (a -> m ()) -> [a] -> m ()
Executes effects and collects results in left-to-right order.
Works best with left-associative monoids.
Note that there is an alternative
mapM' f t = foldr mappend mempty $ mapM f t
that collects results in right-to-left order (effects still left-to-right). It might be preferable for right associative monoids.
forM' :: (Foldable t, Monad m, Monoid b) => t a -> (a -> m b) -> m b Source
Generalized version of forM_ :: Monad m => [a] -> (a -> m ()) -> m ()
thread :: (a -> Cont r b) -> [a] -> Cont r [b] Source
mapM
for the continuation monad. Terribly useful.
zipWithM' :: Monad m => (a -> b -> m c) -> [a] -> [b] -> m [c] Source
Requires both lists to have the same lengths.
mapMaybeM :: (Monad m, Functor m) => (a -> m (Maybe b)) -> [a] -> m [b] Source
A monadic version of
.mapMaybe
:: (a -> Maybe b) -> [a] -> [b]
forMaybeM :: (Monad m, Functor m) => [a] -> (a -> m (Maybe b)) -> m [b] Source
The for
version of mapMaybeM
.
dropWhileM :: Monad m => (a -> m Bool) -> [a] -> m [a] Source
A monadic version of
.dropWhile
:: (a -> Bool) -> [a] -> [a]
finally :: (Error e, MonadError e m) => m a -> m b -> m a Source
Finally for the Error
class. Errors in the finally part take
precedence over prior errors.
:: Monad m | |
=> m a | Acquires resource. Run first. |
-> (a -> m c) | Releases resource. Run last. |
-> m b | Computes result. Run in-between. |
-> m b |
Bracket without failure. Typically used to preserve state.
localState :: MonadState s m => m a -> m a Source
Restore state after computation.
when :: Applicative f => Bool -> f () -> f ()
Conditional execution of Applicative
expressions. For example,
when debug (putStrLn "Debugging")
will output the string Debugging
if the Boolean value debug
is True
, and otherwise do nothing.
unless :: Applicative f => Bool -> f () -> f ()
The reverse of when
.
class (Alternative m, Monad m) => MonadPlus m where
Monads that also support choice and failure.
Nothing
mzero :: m a
the identity of mplus
. It should also satisfy the equations
mzero >>= f = mzero v >> mzero = mzero
mplus :: m a -> m a -> m a
an associative operation
MonadPlus [] | |
MonadPlus P | |
MonadPlus STM | |
MonadPlus ReadPrec | |
MonadPlus ReadP | |
MonadPlus Maybe | |
MonadPlus Get | |
MonadPlus Seq | |
MonadPlus Vector | |
(ArrowApply a, ArrowPlus a) => MonadPlus (ArrowMonad a) | |
Monad m => MonadPlus (MaybeT m) | |
Monad m => MonadPlus (ListT m) | |
MonadPlus m => MonadPlus (IdentityT m) | |
MonadPlus (ReadP t) | |
(Functor m, Applicative m, Monad m) => MonadPlus (ListT m) | |
MonadPlus f => MonadPlus (Alt * f) | |
MonadPlus m => MonadPlus (ReaderT r m) | |
(Monoid w, MonadPlus m) => MonadPlus (WriterT w m) | |
(Monoid w, MonadPlus m) => MonadPlus (WriterT w m) | |
(Monad m, Error e) => MonadPlus (ErrorT e m) | |
(Monad m, Monoid e) => MonadPlus (ExceptT e m) | |
MonadPlus m => MonadPlus (StateT s m) | |
MonadPlus m => MonadPlus (StateT s m) | |
(Monoid w, MonadPlus m) => MonadPlus (RWST r w s m) | |
(Monoid w, MonadPlus m) => MonadPlus (RWST r w s m) |
(<$>) :: Functor f => (a -> b) -> f a -> f b infixl 4
An infix synonym for fmap
.
Examples
Convert from a
to a Maybe
Int
using Maybe
String
show
:
>>>
show <$> Nothing
Nothing>>>
show <$> Just 3
Just "3"
Convert from an
to an Either
Int
Int
Either
Int
String
using show
:
>>>
show <$> Left 17
Left 17>>>
show <$> Right 17
Right "17"
Double each element of a list:
>>>
(*2) <$> [1,2,3]
[2,4,6]
Apply even
to the second element of a pair:
>>>
even <$> (2,2)
(2,True)
(<*>) :: Applicative f => forall a b. f (a -> b) -> f a -> f b
Sequential application.
modify' :: MonadState s m => (s -> s) -> m ()