Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- (==<<) :: Monad m => (a -> b -> m c) -> (m a, m b) -> m c
- whenM :: Monad m => m Bool -> m () -> m ()
- unlessM :: Monad m => m Bool -> m () -> m ()
- guardM :: (Monad m, MonadPlus m) => m Bool -> 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 :: (Foldable f, Monad m) => f (m Bool) -> m Bool
- allM :: (Functor f, Foldable f, Monad m) => f a -> (a -> m Bool) -> m Bool
- or2M :: Monad m => m Bool -> m Bool -> m Bool
- orM :: (Foldable f, Monad m) => f (m Bool) -> m Bool
- anyM :: (Functor f, Foldable f, Monad m) => f a -> (a -> m Bool) -> m Bool
- altM1 :: Monad m => (a -> m (Either err b)) -> [a] -> m (Either err b)
- orEitherM :: (Monoid e, Monad m, Functor m) => [m (Either e b)] -> m (Either e b)
- mapM' :: (Foldable t, Applicative m, Monoid b) => (a -> m b) -> t a -> m b
- forM' :: (Foldable t, Applicative m, Monoid b) => t a -> (a -> m b) -> m b
- mapMM :: (Traversable t, Monad m) => (a -> m b) -> m (t a) -> m (t b)
- forMM :: (Traversable t, Monad m) => m (t a) -> (a -> m b) -> m (t b)
- mapMM_ :: (Foldable t, Monad m) => (a -> m ()) -> m (t a) -> m ()
- forMM_ :: (Foldable t, Monad m) => m (t a) -> (a -> m ()) -> m ()
- mapMaybeM :: Monad m => (a -> m (Maybe b)) -> [a] -> m [b]
- mapMaybeMM :: Monad m => (a -> m (Maybe b)) -> m [a] -> m [b]
- forMaybeM :: Monad m => [a] -> (a -> m (Maybe b)) -> m [b]
- forMaybeMM :: Monad m => m [a] -> (a -> m (Maybe b)) -> m [b]
- dropWhileM :: Monad m => (a -> m Bool) -> [a] -> m [a]
- dropWhileEndM :: Monad m => (a -> m Bool) -> [a] -> m [a]
- partitionM :: (Functor m, Applicative m) => (a -> m Bool) -> [a] -> m ([a], [a])
- fromMaybeMP :: MonadPlus m => Maybe a -> m a
- catMaybesMP :: MonadPlus m => m (Maybe a) -> m a
- scatterMP :: (MonadPlus m, Foldable t) => m (t a) -> m a
- finally :: MonadError e m => m a -> m () -> m a
- tryMaybe :: (MonadError e m, Functor m) => m a -> m (Maybe a)
- tryCatch :: (MonadError e m, Functor m) => m () -> m (Maybe e)
- guardWithError :: MonadError e m => e -> Bool -> m ()
- bracket_ :: Monad m => m a -> (a -> m ()) -> m b -> m b
- localState :: MonadState s m => m a -> m a
- when :: Applicative f => Bool -> f () -> f ()
- unless :: Applicative f => Bool -> f () -> f ()
- class (Alternative m, Monad m) => MonadPlus (m :: Type -> Type) where
- (<$>) :: Functor f => (a -> b) -> f a -> f b
- (<*>) :: Applicative f => f (a -> b) -> f a -> f b
- (<$) :: Functor f => a -> f b -> f a
Documentation
altM1 :: Monad m => (a -> m (Either err b)) -> [a] -> m (Either err b) Source #
Lazy monadic disjunction with Either
truth values.
Returns the last error message if all fail.
orEitherM :: (Monoid e, Monad m, Functor m) => [m (Either e b)] -> m (Either e b) Source #
Lazy monadic disjunction with accumulation of errors in a monoid. Errors are discarded if we succeed.
mapM' :: (Foldable t, Applicative m, Monoid b) => (a -> m b) -> t a -> m b Source #
Generalized version of traverse_ :: Applicative 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, Applicative m, Monoid b) => t a -> (a -> m b) -> m b Source #
Generalized version of for_ :: Applicative m => [a] -> (a -> m ()) -> m ()
mapMM :: (Traversable t, Monad m) => (a -> m b) -> m (t a) -> m (t b) Source #
forMM :: (Traversable t, Monad m) => m (t a) -> (a -> m b) -> m (t b) Source #
mapMaybeM :: Monad m => (a -> m (Maybe b)) -> [a] -> m [b] Source #
A monadic version of
.mapMaybe
:: (a -> Maybe b) -> [a] -> [b]
mapMaybeMM :: Monad m => (a -> m (Maybe b)) -> m [a] -> m [b] Source #
A version of
with a computation for the input list.mapMaybeM
forMaybeMM :: Monad m => m [a] -> (a -> m (Maybe b)) -> m [b] Source #
The for
version of mapMaybeMM
.
dropWhileM :: Monad m => (a -> m Bool) -> [a] -> m [a] Source #
A monadic version of
.dropWhile
:: (a -> Bool) -> [a] -> [a]
dropWhileEndM :: Monad m => (a -> m Bool) -> [a] -> m [a] Source #
A monadic version of
.
Effects happen starting at the end of the list until dropWhileEnd
:: (a -> Bool) -> [a] -> m [a]p
becomes false.
partitionM :: (Functor m, Applicative m) => (a -> m Bool) -> [a] -> m ([a], [a]) Source #
A `monadic'
version of @partition
:: (a -> Bool) -> [a] -> ([a],[a])
catMaybesMP :: MonadPlus m => m (Maybe a) -> m a Source #
scatterMP :: (MonadPlus m, Foldable t) => m (t a) -> m a Source #
Branch over elements of a monadic Foldable
data structure.
finally :: MonadError e m => m a -> m () -> m a Source #
Finally for the Error
class. Errors in the finally part take
precedence over prior errors.
tryMaybe :: (MonadError e m, Functor m) => m a -> m (Maybe a) Source #
Try a computation, return Nothing
if an Error
occurs.
tryCatch :: (MonadError e m, Functor m) => m () -> m (Maybe e) Source #
Run a command, catch the exception and return it.
guardWithError :: MonadError e m => e -> Bool -> m () Source #
Like guard
, but raise given error when condition fails.
:: Monad m | |
=> m a | Acquires resource. Run first. |
-> (a -> m ()) | 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 :: Type -> Type) where #
Monads that also support choice and failure.
Nothing
The identity of mplus
. It should also satisfy the equations
mzero >>= f = mzero v >> mzero = mzero
The default definition is
mzero = empty
An associative operation. The default definition is
mplus = (<|>
)
Instances
(<$>) :: Functor f => (a -> b) -> f a -> f b infixl 4 #
An infix synonym for fmap
.
The name of this operator is an allusion to $
.
Note the similarities between their types:
($) :: (a -> b) -> a -> b (<$>) :: Functor f => (a -> b) -> f a -> f b
Whereas $
is function application, <$>
is function
application lifted over a Functor
.
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 => f (a -> b) -> f a -> f b infixl 4 #