Safe Haskell  Safe 

Language  Haskell2010 
Synopsis
 guard :: Alternative f => Bool > f ()
 join :: Monad m => m (m a) > m a
 class Applicative m => Monad (m :: * > *) where
 class Functor (f :: * > *) where
 mapM :: (Traversable t, Monad m) => (a > m b) > t a > m (t b)
 sequence :: (Traversable t, Monad m) => t (m a) > m (t a)
 mfilter :: MonadPlus m => (a > Bool) > m a > m a
 (<$!>) :: Monad m => (a > b) > m a > m b
 unless :: Applicative f => Bool > f () > f ()
 replicateM_ :: Applicative m => Int > m a > m ()
 replicateM :: Applicative m => Int > m a > m [a]
 foldM_ :: (Foldable t, Monad m) => (b > a > m b) > b > t a > m ()
 foldM :: (Foldable t, Monad m) => (b > a > m b) > b > t a > m b
 zipWithM_ :: Applicative m => (a > b > m c) > [a] > [b] > m ()
 zipWithM :: Applicative m => (a > b > m c) > [a] > [b] > m [c]
 mapAndUnzipM :: Applicative m => (a > m (b, c)) > [a] > m ([b], [c])
 forever :: Applicative f => f a > f b
 (<=<) :: Monad m => (b > m c) > (a > m b) > a > m c
 (>=>) :: Monad m => (a > m b) > (b > m c) > a > m c
 filterM :: Applicative m => (a > m Bool) > [a] > m [a]
 forM :: (Traversable t, Monad m) => t a > (a > m b) > m (t b)
 msum :: (Foldable t, MonadPlus m) => t (m a) > m a
 sequence_ :: (Foldable t, Monad m) => t (m a) > m ()
 forM_ :: (Foldable t, Monad m) => t a > (a > m b) > m ()
 mapM_ :: (Foldable t, Monad m) => (a > m b) > t a > m ()
 void :: Functor f => f a > f ()
 ap :: Monad m => m (a > b) > m a > m b
 liftM5 :: Monad m => (a1 > a2 > a3 > a4 > a5 > r) > m a1 > m a2 > m a3 > m a4 > m a5 > m r
 liftM4 :: Monad m => (a1 > a2 > a3 > a4 > r) > m a1 > m a2 > m a3 > m a4 > m r
 liftM3 :: Monad m => (a1 > a2 > a3 > r) > m a1 > m a2 > m a3 > m r
 liftM2 :: Monad m => (a1 > a2 > r) > m a1 > m a2 > m r
 liftM :: Monad m => (a1 > r) > m a1 > m r
 when :: Applicative f => Bool > f () > f ()
 (=<<) :: Monad m => (a > m b) > m a > m b
 class (Alternative m, Monad m) => MonadPlus (m :: * > *) where
 module Control.Monad.Fail
 class (Functor f, Monad m) => MonadFree f m where
 data Free f a
 isPure :: Free f a > Bool
 isImpure :: Free f a > Bool
 foldFree :: Functor f => (a > b) > (f b > b) > Free f a > b
 evalFree :: (a > b) > (f (Free f a) > b) > Free f a > b
 mapFree :: (Functor f, Functor g) => (f (Free g a) > g (Free g a)) > Free f a > Free g a
 mapFreeM :: (Traversable f, Functor g, Monad m) => (f (Free g a) > m (g (Free g a))) > Free f a > m (Free g a)
 mapFreeM' :: (Functor f, Traversable g, Monad m) => (forall a. f a > m (g a)) > Free f a > m (Free g a)
 foldFreeM :: (Traversable f, Monad m) => (a > m b) > (f b > m b) > Free f a > m b
 induce :: (Functor f, Monad m) => (forall a. f a > m a) > Free f a > m a
 newtype FreeT f m a = FreeT {}
 foldFreeT :: (Traversable f, Monad m) => (a > m b) > (f b > m b) > FreeT f m a > m b
 foldFreeT' :: (Traversable f, Monad m) => (a > b) > (f b > b) > FreeT f m a > m b
 mapFreeT :: (Functor f, Functor m) => (forall a. m a > m' a) > FreeT f m a > FreeT f m' a
 foldFreeA :: (Traversable f, Applicative m) => (a > m b) > m (f b > b) > Free f a > m b
 mapFreeA :: (Traversable f, Functor g, Applicative m) => m (f (Free g a) > g (Free g a)) > Free f a > m (Free g a)
 trans :: MonadFree f m => Free f a > m a
 trans' :: (Functor f, Monad m) => m (Free f a) > FreeT f m a
 untrans :: (Traversable f, Monad m) => FreeT f m a > m (Free f a)
 liftFree :: (Functor f, Monad m) => (a > Free f b) > a > FreeT f m b
Documentation
guard :: Alternative f => Bool > f () #
Conditional failure of Alternative
computations. Defined by
guard True =pure
() guard False =empty
Examples
Common uses of guard
include conditionally signaling an error in
an error monad and conditionally rejecting the current choice in an
Alternative
based parser.
As an example of signaling an error in the error monad Maybe
,
consider a safe division function safeDiv x y
that returns
Nothing
when the denominator y
is zero and
otherwise. For example:Just
(x `div`
y)
>>> safeDiv 4 0 Nothing >>> safeDiv 4 2 Just 2
A definition of safeDiv
using guards, but not guard
:
safeDiv :: Int > Int > Maybe Int safeDiv x y  y /= 0 = Just (x `div` y)  otherwise = Nothing
A definition of safeDiv
using guard
and Monad
do
notation:
safeDiv :: Int > Int > Maybe Int safeDiv x y = do guard (y /= 0) return (x `div` y)
join :: Monad m => m (m a) > m a #
The join
function is the conventional monad join operator. It
is used to remove one level of monadic structure, projecting its
bound argument into the outer level.
class Applicative m => Monad (m :: * > *) where #
The Monad
class defines the basic operations over a monad,
a concept from a branch of mathematics known as category theory.
From the perspective of a Haskell programmer, however, it is best to
think of a monad as an abstract datatype of actions.
Haskell's do
expressions provide a convenient syntax for writing
monadic expressions.
Instances of Monad
should satisfy the following laws:
Furthermore, the Monad
and Applicative
operations should relate as follows:
The above laws imply:
and that pure
and (<*>
) satisfy the applicative functor laws.
The instances of Monad
for lists, Maybe
and IO
defined in the Prelude satisfy these laws.
(>>=) :: m a > (a > m b) > m b infixl 1 #
Sequentially compose two actions, passing any value produced by the first as an argument to the second.
(>>) :: m a > m b > m b infixl 1 #
Sequentially compose two actions, discarding any value produced by the first, like sequencing operators (such as the semicolon) in imperative languages.
Inject a value into the monadic type.
Instances
Monad []  Since: base2.1 
Monad Maybe  Since: base2.1 
Monad IO  Since: base2.1 
Monad Par1  Since: base4.9.0.0 
Monad Identity  Since: base4.8.0.0 
Monad First  
Monad Last  
Monad Dual  Since: base4.8.0.0 
Monad Sum  Since: base4.8.0.0 
Monad Product  Since: base4.8.0.0 
Monad ReadP  Since: base2.1 
Monad NonEmpty  Since: base4.9.0.0 
Monad P  Since: base2.1 
Monad (Either e)  Since: base4.4.0.0 
Monad (U1 :: * > *)  Since: base4.9.0.0 
Monoid a => Monad ((,) a)  Since: base4.9.0.0 
Monad m => Monad (WrappedMonad m)  
Defined in Control.Applicative (>>=) :: WrappedMonad m a > (a > WrappedMonad m b) > WrappedMonad m b # (>>) :: WrappedMonad m a > WrappedMonad m b > WrappedMonad m b # return :: a > WrappedMonad m a # fail :: String > WrappedMonad m a #  
ArrowApply a => Monad (ArrowMonad a)  Since: base2.1 
Defined in Control.Arrow (>>=) :: ArrowMonad a a0 > (a0 > ArrowMonad a b) > ArrowMonad a b # (>>) :: ArrowMonad a a0 > ArrowMonad a b > ArrowMonad a b # return :: a0 > ArrowMonad a a0 # fail :: String > ArrowMonad a a0 #  
Monad (Proxy :: * > *)  Since: base4.7.0.0 
Functor f => Monad (Free f) #  
Monad (C mu) #  
Monad f => Monad (Rec1 f)  Since: base4.9.0.0 
Monad f => Monad (Alt f)  
Monad m => Monad (StateT s m)  
(Functor f, Monad m) => Monad (FreeT f m) #  
Monad ((>) r :: * > *)  Since: base2.1 
(Monad f, Monad g) => Monad (f :*: g)  Since: base4.9.0.0 
Monad f => Monad (M1 i c f)  Since: base4.9.0.0 
class Functor (f :: * > *) where #
The Functor
class is used for types that can be mapped over.
Instances of Functor
should satisfy the following laws:
fmap id == id fmap (f . g) == fmap f . fmap g
The instances of Functor
for lists, Maybe
and IO
satisfy these laws.
Instances
Functor []  Since: base2.1 
Functor Maybe  Since: base2.1 
Functor IO  Since: base2.1 
Functor Par1  
Functor ZipList  
Functor Identity  Since: base4.8.0.0 
Functor First  
Functor Last  
Functor Dual  Since: base4.8.0.0 
Functor Sum  Since: base4.8.0.0 
Functor Product  Since: base4.8.0.0 
Functor ReadP  Since: base2.1 
Functor NonEmpty  Since: base4.9.0.0 
Functor P  
Defined in Text.ParserCombinators.ReadP  
Functor (Either a)  Since: base3.0 
Functor (V1 :: * > *)  Since: base4.9.0.0 
Functor (U1 :: * > *)  Since: base4.9.0.0 
Functor ((,) a)  Since: base2.1 
Functor (Array i)  Since: base2.1 
Monad m => Functor (WrappedMonad m)  Since: base2.1 
Defined in Control.Applicative fmap :: (a > b) > WrappedMonad m a > WrappedMonad m b # (<$) :: a > WrappedMonad m b > WrappedMonad m a #  
Arrow a => Functor (ArrowMonad a)  Since: base4.6.0.0 
Defined in Control.Arrow fmap :: (a0 > b) > ArrowMonad a a0 > ArrowMonad a b # (<$) :: a0 > ArrowMonad a b > ArrowMonad a a0 #  
Functor (Proxy :: * > *)  Since: base4.7.0.0 
Functor f => Functor (Free f) #  
Functor (C mu) #  
Functor f => Functor (Rec1 f)  
Functor (URec Char :: * > *)  
Functor (URec Double :: * > *)  
Functor (URec Float :: * > *)  
Functor (URec Int :: * > *)  
Functor (URec Word :: * > *)  
Functor (URec (Ptr ()) :: * > *)  
Arrow a => Functor (WrappedArrow a b)  Since: base2.1 
Defined in Control.Applicative fmap :: (a0 > b0) > WrappedArrow a b a0 > WrappedArrow a b b0 # (<$) :: a0 > WrappedArrow a b b0 > WrappedArrow a b a0 #  
Functor (Const m :: * > *)  Since: base2.1 
Functor f => Functor (Alt f)  
Functor m => Functor (StateT s m)  
(Functor f, Functor m) => Functor (FreeT f m) #  
Functor ((>) r :: * > *)  Since: base2.1 
Functor (K1 i c :: * > *)  
(Functor f, Functor g) => Functor (f :+: g)  
(Functor f, Functor g) => Functor (f :*: g)  
Functor f => Functor (M1 i c f)  
(Functor f, Functor g) => Functor (f :.: g)  
mapM :: (Traversable t, Monad m) => (a > m b) > t a > m (t b) #
Map each element of a structure to a monadic action, evaluate
these actions from left to right, and collect the results. For
a version that ignores the results see mapM_
.
sequence :: (Traversable t, Monad m) => t (m a) > m (t a) #
Evaluate each monadic action in the structure from left to
right, and collect the results. For a version that ignores the
results see sequence_
.
unless :: Applicative f => Bool > f () > f () #
The reverse of when
.
replicateM_ :: Applicative m => Int > m a > m () #
Like replicateM
, but discards the result.
replicateM :: Applicative m => Int > m a > m [a] #
performs the action replicateM
n actn
times,
gathering the results.
foldM_ :: (Foldable t, Monad m) => (b > a > m b) > b > t a > m () #
Like foldM
, but discards the result.
foldM :: (Foldable t, Monad m) => (b > a > m b) > b > t a > m b #
The foldM
function is analogous to foldl
, except that its result is
encapsulated in a monad. Note that foldM
works from lefttoright over
the list arguments. This could be an issue where (
and the `folded
function' are not commutative.>>
)
foldM f a1 [x1, x2, ..., xm] == do a2 < f a1 x1 a3 < f a2 x2 ... f am xm
If righttoleft evaluation is required, the input list should be reversed.
zipWithM_ :: Applicative m => (a > b > m c) > [a] > [b] > m () #
zipWithM :: Applicative m => (a > b > m c) > [a] > [b] > m [c] #
mapAndUnzipM :: Applicative m => (a > m (b, c)) > [a] > m ([b], [c]) #
The mapAndUnzipM
function maps its first argument over a list, returning
the result as a pair of lists. This function is mainly used with complicated
data structures or a statetransforming monad.
forever :: Applicative f => f a > f b #
repeats the action infinitely.forever
act
(>=>) :: Monad m => (a > m b) > (b > m c) > a > m c infixr 1 #
Lefttoright Kleisli composition of monads.
filterM :: Applicative m => (a > m Bool) > [a] > m [a] #
This generalizes the listbased filter
function.
forM :: (Traversable t, Monad m) => t a > (a > m b) > m (t b) #
sequence_ :: (Foldable t, Monad m) => t (m a) > m () #
Evaluate each monadic action in the structure from left to right,
and ignore the results. For a version that doesn't ignore the
results see sequence
.
As of base 4.8.0.0, sequence_
is just sequenceA_
, specialized
to Monad
.
void :: Functor f => f a > f () #
discards or ignores the result of evaluation, such
as the return value of an void
valueIO
action.
Examples
Replace the contents of a
with unit:Maybe
Int
>>>
void Nothing
Nothing>>>
void (Just 3)
Just ()
Replace the contents of an
with unit,
resulting in an Either
Int
Int
:Either
Int
'()'
>>>
void (Left 8675309)
Left 8675309>>>
void (Right 8675309)
Right ()
Replace every element of a list with unit:
>>>
void [1,2,3]
[(),(),()]
Replace the second element of a pair with unit:
>>>
void (1,2)
(1,())
Discard the result of an IO
action:
>>>
mapM print [1,2]
1 2 [(),()]>>>
void $ mapM print [1,2]
1 2
liftM5 :: Monad m => (a1 > a2 > a3 > a4 > a5 > r) > m a1 > m a2 > m a3 > m a4 > m a5 > m r #
Promote a function to a monad, scanning the monadic arguments from
left to right (cf. liftM2
).
liftM4 :: Monad m => (a1 > a2 > a3 > a4 > r) > m a1 > m a2 > m a3 > m a4 > m r #
Promote a function to a monad, scanning the monadic arguments from
left to right (cf. liftM2
).
liftM3 :: Monad m => (a1 > a2 > a3 > r) > m a1 > m a2 > m a3 > m r #
Promote a function to a monad, scanning the monadic arguments from
left to right (cf. liftM2
).
liftM2 :: Monad m => (a1 > a2 > r) > m a1 > m a2 > m r #
Promote a function to a monad, scanning the monadic arguments from left to right. For example,
liftM2 (+) [0,1] [0,2] = [0,2,1,3] liftM2 (+) (Just 1) Nothing = Nothing
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.
(=<<) :: Monad m => (a > m b) > m a > m b infixr 1 #
Same as >>=
, but with the arguments interchanged.
class (Alternative m, Monad m) => MonadPlus (m :: * > *) where #
Monads that also support choice and failure.
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
MonadPlus []  Since: base2.1 
MonadPlus Maybe  Since: base2.1 
MonadPlus IO  Since: base4.9.0.0 
MonadPlus ReadP  Since: base2.1 
MonadPlus P  Since: base2.1 
Defined in Text.ParserCombinators.ReadP  
MonadPlus (U1 :: * > *)  Since: base4.9.0.0 
(ArrowApply a, ArrowPlus a) => MonadPlus (ArrowMonad a)  Since: base4.6.0.0 
Defined in Control.Arrow mzero :: ArrowMonad a a0 # mplus :: ArrowMonad a a0 > ArrowMonad a a0 > ArrowMonad a a0 #  
MonadPlus (Proxy :: * > *)  Since: base4.9.0.0 
MonadPlus mu => MonadPlus (C mu) #  
MonadPlus f => MonadPlus (Rec1 f)  Since: base4.9.0.0 
MonadPlus f => MonadPlus (Alt f)  
MonadPlus m => MonadPlus (StateT s m)  
(Functor f, Monad m, MonadPlus m) => MonadPlus (FreeT f m) #  
(MonadPlus f, MonadPlus g) => MonadPlus (f :*: g)  Since: base4.9.0.0 
MonadPlus f => MonadPlus (M1 i c f)  Since: base4.9.0.0 
module Control.Monad.Fail
Free Monads
class (Functor f, Monad m) => MonadFree f m where Source #
This type class generalizes over encodings of Free Monads.
:: m a  
> m (Either a (f (m a))) 

:: f (m a)  
> m a  Wraps a side effect into a monadic computation 
Instances
Functor f => MonadFree f (Free f) Source #  
Functor f => MonadFree f (C (Free f)) Source #  
Functor f => Monad (Free f) Source #  
Functor f => Functor (Free f) Source #  
Functor f => Applicative (Free f) Source #  
(Functor f, Foldable f) => Foldable (Free f) Source #  
Defined in Control.Monad.Free fold :: Monoid m => Free f m > m # foldMap :: Monoid m => (a > m) > Free f a > m # foldr :: (a > b > b) > b > Free f a > b # foldr' :: (a > b > b) > b > Free f a > b # foldl :: (b > a > b) > b > Free f a > b # foldl' :: (b > a > b) > b > Free f a > b # foldr1 :: (a > a > a) > Free f a > a # foldl1 :: (a > a > a) > Free f a > a # elem :: Eq a => a > Free f a > Bool # maximum :: Ord a => Free f a > a # minimum :: Ord a => Free f a > a #  
Traversable f => Traversable (Free f) Source #  
Eq1 f => Eq1 (Free f) Source #  
Ord1 f => Ord1 (Free f) Source #  
Defined in Control.Monad.Free  
(Eq a, Eq1 f) => Eq (Free f a) Source #  
(Ord a, Ord1 f) => Ord (Free f a) Source #  
Defined in Control.Monad.Free  
(Show a, Show1 f) => Show (Free f a) Source #  
Generic (Free f a) Source #  
type Rep (Free f a) Source #  
Defined in Control.Monad.Free type Rep (Free f a) = D1 (MetaData "Free" "Control.Monad.Free" "controlmonadfree0.6.2D8gRCj9jdnL78y3kztZ3ka" False) (C1 (MetaCons "Impure" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (f (Free f a)))) :+: C1 (MetaCons "Pure" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a))) 
mapFree :: (Functor f, Functor g) => (f (Free g a) > g (Free g a)) > Free f a > Free g a Source #
mapFreeM :: (Traversable f, Functor g, Monad m) => (f (Free g a) > m (g (Free g a))) > Free f a > m (Free g a) Source #
mapFreeM' :: (Functor f, Traversable g, Monad m) => (forall a. f a > m (g a)) > Free f a > m (Free g a) Source #
Monad Morphisms
Free Monad Transformers
Instances
(Monad m, Functor f) => MonadFree f (C (FreeT f m)) Source #  
(Functor f, Monad m) => MonadFree f (FreeT f m) Source #  
Functor f => MonadTrans (FreeT f) Source #  
Defined in Control.Monad.Free  
(Functor f, Monad m) => Monad (FreeT f m) Source #  
(Functor f, Functor m) => Functor (FreeT f m) Source #  
(Functor f, Functor a, Monad a) => Applicative (FreeT f a) Source #  
(Traversable m, Traversable f) => Foldable (FreeT f m) Source #  
Defined in Control.Monad.Free fold :: Monoid m0 => FreeT f m m0 > m0 # foldMap :: Monoid m0 => (a > m0) > FreeT f m a > m0 # foldr :: (a > b > b) > b > FreeT f m a > b # foldr' :: (a > b > b) > b > FreeT f m a > b # foldl :: (b > a > b) > b > FreeT f m a > b # foldl' :: (b > a > b) > b > FreeT f m a > b # foldr1 :: (a > a > a) > FreeT f m a > a # foldl1 :: (a > a > a) > FreeT f m a > a # toList :: FreeT f m a > [a] # length :: FreeT f m a > Int # elem :: Eq a => a > FreeT f m a > Bool # maximum :: Ord a => FreeT f m a > a # minimum :: Ord a => FreeT f m a > a #  
(Traversable m, Traversable f) => Traversable (FreeT f m) Source #  
Defined in Control.Monad.Free  
(Functor f, Monad m, MonadIO m) => MonadIO (FreeT f m) Source #  
Defined in Control.Monad.Free  
(Functor f, Functor m, Monad m, MonadPlus m) => Alternative (FreeT f m) Source #  
(Functor f, Monad m, MonadPlus m) => MonadPlus (FreeT f m) Source #  
foldFreeT' :: (Traversable f, Monad m) => (a > b) > (f b > b) > FreeT f m a > m b Source #
mapFreeT :: (Functor f, Functor m) => (forall a. m a > m' a) > FreeT f m a > FreeT f m' a Source #
foldFreeA :: (Traversable f, Applicative m) => (a > m b) > m (f b > b) > Free f a > m b Source #
mapFreeA :: (Traversable f, Functor g, Applicative m) => m (f (Free g a) > g (Free g a)) > Free f a > m (Free g a) Source #