Synopsis

# Documentation

guard :: Alternative f => Bool -> f () #

Conditional failure of Alternative computations. Defined by

guard True  = pure ()
guard False = empty


#### Examples

Expand

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 Just (x div y) otherwise. For example:

>>> 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:

• return a >>= k  =  k a
• m >>= return  =  m
• m >>= (\x -> k x >>= h)  =  (m >>= k) >>= h

Furthermore, the Monad and Applicative operations should relate as follows:

• pure = return
• (<*>) = ap

The above laws imply:

• fmap f xs  =  xs >>= return . f
• (>>) = (*>)

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.

Minimal complete definition

(>>=)

Methods

(>>=) :: 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.

return :: a -> m a #

Inject a value into the monadic type.

Instances

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.

Minimal complete definition

fmap

Methods

fmap :: (a -> b) -> f a -> f b #

Instances
 Functor [] Since: base-2.1 Instance detailsDefined in GHC.Base Methodsfmap :: (a -> b) -> [a] -> [b] #(<$) :: a -> [b] -> [a] # Since: base-2.1 Instance detailsDefined in GHC.Base Methodsfmap :: (a -> b) -> Maybe a -> Maybe b #(<$) :: a -> Maybe b -> Maybe a # Since: base-2.1 Instance detailsDefined in GHC.Base Methodsfmap :: (a -> b) -> IO a -> IO b #(<$) :: a -> IO b -> IO a # Instance detailsDefined in GHC.Generics Methodsfmap :: (a -> b) -> Par1 a -> Par1 b #(<$) :: a -> Par1 b -> Par1 a # Instance detailsDefined in Control.Applicative Methodsfmap :: (a -> b) -> ZipList a -> ZipList b #(<$) :: a -> ZipList b -> ZipList a # Since: base-4.8.0.0 Instance detailsDefined in Data.Functor.Identity Methodsfmap :: (a -> b) -> Identity a -> Identity b #(<$) :: a -> Identity b -> Identity a # Instance detailsDefined in Data.Monoid Methodsfmap :: (a -> b) -> First a -> First b #(<$) :: a -> First b -> First a # Instance detailsDefined in Data.Monoid Methodsfmap :: (a -> b) -> Last a -> Last b #(<$) :: a -> Last b -> Last a # Since: base-4.8.0.0 Instance detailsDefined in Data.Semigroup.Internal Methodsfmap :: (a -> b) -> Dual a -> Dual b #(<$) :: a -> Dual b -> Dual a # Since: base-4.8.0.0 Instance detailsDefined in Data.Semigroup.Internal Methodsfmap :: (a -> b) -> Sum a -> Sum b #(<$) :: a -> Sum b -> Sum a # Since: base-4.8.0.0 Instance detailsDefined in Data.Semigroup.Internal Methodsfmap :: (a -> b) -> Product a -> Product b #(<$) :: a -> Product b -> Product a # Since: base-2.1 Instance detailsDefined in Text.ParserCombinators.ReadP Methodsfmap :: (a -> b) -> ReadP a -> ReadP b #(<$) :: a -> ReadP b -> ReadP a # Since: base-4.9.0.0 Instance detailsDefined in GHC.Base Methodsfmap :: (a -> b) -> NonEmpty a -> NonEmpty b #(<$) :: a -> NonEmpty b -> NonEmpty a # Instance detailsDefined in Text.ParserCombinators.ReadP Methodsfmap :: (a -> b) -> P a -> P b #(<$) :: a -> P b -> P a # Since: base-3.0 Instance detailsDefined in Data.Either Methodsfmap :: (a0 -> b) -> Either a a0 -> Either a b #(<$) :: a0 -> Either a b -> Either a a0 # Functor (V1 :: * -> *) Since: base-4.9.0.0 Instance detailsDefined in GHC.Generics Methodsfmap :: (a -> b) -> V1 a -> V1 b #(<$) :: a -> V1 b -> V1 a # Functor (U1 :: * -> *) Since: base-4.9.0.0 Instance detailsDefined in GHC.Generics Methodsfmap :: (a -> b) -> U1 a -> U1 b #(<$) :: a -> U1 b -> U1 a # Functor ((,) a) Since: base-2.1 Instance detailsDefined in GHC.Base Methodsfmap :: (a0 -> b) -> (a, a0) -> (a, b) #(<$) :: a0 -> (a, b) -> (a, a0) # Functor (Array i) Since: base-2.1 Instance detailsDefined in GHC.Arr Methodsfmap :: (a -> b) -> Array i a -> Array i b #(<$) :: a -> Array i b -> Array i a # Monad m => Functor (WrappedMonad m) Since: base-2.1 Instance detailsDefined in Control.Applicative Methodsfmap :: (a -> b) -> WrappedMonad m a -> WrappedMonad m b #(<$) :: a -> WrappedMonad m b -> WrappedMonad m a # Arrow a => Functor (ArrowMonad a) Since: base-4.6.0.0 Instance detailsDefined in Control.Arrow Methodsfmap :: (a0 -> b) -> ArrowMonad a a0 -> ArrowMonad a b #(<$) :: a0 -> ArrowMonad a b -> ArrowMonad a a0 # Functor (Proxy :: * -> *) Since: base-4.7.0.0 Instance detailsDefined in Data.Proxy Methodsfmap :: (a -> b) -> Proxy a -> Proxy b #(<$) :: a -> Proxy b -> Proxy a # Functor f => Functor (Free f) # Instance detailsDefined in Control.Monad.Free Methodsfmap :: (a -> b) -> Free f a -> Free f b #(<$) :: a -> Free f b -> Free f a # Functor (C mu) # Instance detailsDefined in Control.Monad.Free.Improve Methodsfmap :: (a -> b) -> C mu a -> C mu b #(<$) :: a -> C mu b -> C mu a # Functor f => Functor (Rec1 f) Instance detailsDefined in GHC.Generics Methodsfmap :: (a -> b) -> Rec1 f a -> Rec1 f b #(<$) :: a -> Rec1 f b -> Rec1 f a # Functor (URec Char :: * -> *) Instance detailsDefined in GHC.Generics Methodsfmap :: (a -> b) -> URec Char a -> URec Char b #(<$) :: a -> URec Char b -> URec Char a # Functor (URec Double :: * -> *) Instance detailsDefined in GHC.Generics Methodsfmap :: (a -> b) -> URec Double a -> URec Double b #(<$) :: a -> URec Double b -> URec Double a # Functor (URec Float :: * -> *) Instance detailsDefined in GHC.Generics Methodsfmap :: (a -> b) -> URec Float a -> URec Float b #(<$) :: a -> URec Float b -> URec Float a # Functor (URec Int :: * -> *) Instance detailsDefined in GHC.Generics Methodsfmap :: (a -> b) -> URec Int a -> URec Int b #(<$) :: a -> URec Int b -> URec Int a # Functor (URec Word :: * -> *) Instance detailsDefined in GHC.Generics Methodsfmap :: (a -> b) -> URec Word a -> URec Word b #(<$) :: a -> URec Word b -> URec Word a # Functor (URec (Ptr ()) :: * -> *) Instance detailsDefined in GHC.Generics Methodsfmap :: (a -> b) -> URec (Ptr ()) a -> URec (Ptr ()) b #(<$) :: a -> URec (Ptr ()) b -> URec (Ptr ()) a # Arrow a => Functor (WrappedArrow a b) Since: base-2.1 Instance detailsDefined in Control.Applicative Methodsfmap :: (a0 -> b0) -> WrappedArrow a b a0 -> WrappedArrow a b b0 #(<$) :: a0 -> WrappedArrow a b b0 -> WrappedArrow a b a0 # Functor (Const m :: * -> *) Since: base-2.1 Instance detailsDefined in Data.Functor.Const Methodsfmap :: (a -> b) -> Const m a -> Const m b #(<$) :: a -> Const m b -> Const m a # Functor f => Functor (Alt f) Instance detailsDefined in Data.Semigroup.Internal Methodsfmap :: (a -> b) -> Alt f a -> Alt f b #(<$) :: a -> Alt f b -> Alt f a # Functor m => Functor (StateT s m) Instance detailsDefined in Control.Monad.Trans.State.Lazy Methodsfmap :: (a -> b) -> StateT s m a -> StateT s m b #(<$) :: a -> StateT s m b -> StateT s m a # (Functor f, Functor m) => Functor (FreeT f m) # Instance detailsDefined in Control.Monad.Free Methodsfmap :: (a -> b) -> FreeT f m a -> FreeT f m b #(<$) :: a -> FreeT f m b -> FreeT f m a # Functor ((->) r :: * -> *) Since: base-2.1 Instance detailsDefined in GHC.Base Methodsfmap :: (a -> b) -> (r -> a) -> r -> b #(<$) :: a -> (r -> b) -> r -> a # Functor (K1 i c :: * -> *) Instance detailsDefined in GHC.Generics Methodsfmap :: (a -> b) -> K1 i c a -> K1 i c b #(<$) :: a -> K1 i c b -> K1 i c a # (Functor f, Functor g) => Functor (f :+: g) Instance detailsDefined in GHC.Generics Methodsfmap :: (a -> b) -> (f :+: g) a -> (f :+: g) b #(<$) :: a -> (f :+: g) b -> (f :+: g) a # (Functor f, Functor g) => Functor (f :*: g) Instance detailsDefined in GHC.Generics Methodsfmap :: (a -> b) -> (f :*: g) a -> (f :*: g) b #(<$) :: a -> (f :*: g) b -> (f :*: g) a # Functor f => Functor (M1 i c f) Instance detailsDefined in GHC.Generics Methodsfmap :: (a -> b) -> M1 i c f a -> M1 i c f b #(<$) :: a -> M1 i c f b -> M1 i c f a # (Functor f, Functor g) => Functor (f :.: g) Instance detailsDefined in GHC.Generics Methodsfmap :: (a -> b) -> (f :.: g) a -> (f :.: g) b #(<$) :: a -> (f :.: g) b -> (f :.: g) a #

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_.

mfilter :: MonadPlus m => (a -> Bool) -> m a -> m a #

Direct MonadPlus equivalent of filter filter = (mfilter:: (a -> Bool) -> [a] -> [a] applicable to any MonadPlus, for example mfilter odd (Just 1) == Just 1 mfilter odd (Just 2) == Nothing

(<$!>) :: Monad m => (a -> b) -> m a -> m b infixl 4 # Strict version of <$>.

Since: base-4.8.0.0

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] #

replicateM n act performs the action n 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 left-to-right 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 right-to-left evaluation is required, the input list should be reversed.

Note: foldM is the same as foldlM

zipWithM_ :: Applicative m => (a -> b -> m c) -> [a] -> [b] -> m () #

zipWithM_ is the extension of zipWithM which ignores the final result.

zipWithM :: Applicative m => (a -> b -> m c) -> [a] -> [b] -> m [c] #

The zipWithM function generalizes zipWith to arbitrary applicative functors.

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 state-transforming monad.

forever :: Applicative f => f a -> f b #

forever act repeats the action infinitely.

(<=<) :: Monad m => (b -> m c) -> (a -> m b) -> a -> m c infixr 1 #

Right-to-left Kleisli composition of monads. (>=>), 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

(>=>) :: Monad m => (a -> m b) -> (b -> m c) -> a -> m c infixr 1 #

filterM :: Applicative m => (a -> m Bool) -> [a] -> m [a] #

This generalizes the list-based filter function.

forM :: (Traversable t, Monad m) => t a -> (a -> m b) -> m (t b) #

forM is mapM with its arguments flipped. For a version that ignores the results see forM_.

msum :: (Foldable t, MonadPlus m) => t (m a) -> m a #

The sum of a collection of actions, generalizing concat. As of base 4.8.0.0, msum is just asum, specialized to MonadPlus.

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.

forM_ :: (Foldable t, Monad m) => t a -> (a -> m b) -> m () #

forM_ is mapM_ with its arguments flipped. For a version that doesn't ignore the results see forM.

As of base 4.8.0.0, forM_ is just for_, specialized to Monad.

mapM_ :: (Foldable t, Monad m) => (a -> m b) -> t a -> m () #

Map each element of a structure to a monadic action, evaluate these actions from left to right, and ignore the results. For a version that doesn't ignore the results see mapM.

As of base 4.8.0.0, mapM_ is just traverse_, specialized to Monad.

void :: Functor f => f a -> f () #

void value discards or ignores the result of evaluation, such as the return value of an IO action.

#### Examples

Expand

Replace the contents of a Maybe Int with unit:

>>> void Nothing
Nothing
>>> void (Just 3)
Just ()


Replace the contents of an Either Int Int with unit, resulting in an 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  ap :: Monad m => m (a -> b) -> m a -> m b # In many situations, the liftM operations can be replaced by uses of ap, which promotes function application. return f ap x1 ap ... ap xn is equivalent to liftMn f x1 x2 ... xn 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 liftM :: Monad m => (a1 -> r) -> m a1 -> m r # Promote a function to a monad. 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. Methods mzero :: m a # The identity of mplus. It should also satisfy the equations mzero >>= f = mzero v >> mzero = mzero The default definition is mzero = empty  mplus :: m a -> m a -> m a # An associative operation. The default definition is mplus = (<|>)  Instances  Since: base-2.1 Instance detailsDefined in GHC.Base Methodsmzero :: [a] #mplus :: [a] -> [a] -> [a] # Since: base-2.1 Instance detailsDefined in GHC.Base Methodsmzero :: Maybe a #mplus :: Maybe a -> Maybe a -> Maybe a # Since: base-4.9.0.0 Instance detailsDefined in GHC.Base Methodsmzero :: IO a #mplus :: IO a -> IO a -> IO a # Since: base-2.1 Instance detailsDefined in Text.ParserCombinators.ReadP Methodsmzero :: ReadP a #mplus :: ReadP a -> ReadP a -> ReadP a # Since: base-2.1 Instance detailsDefined in Text.ParserCombinators.ReadP Methodsmzero :: P a #mplus :: P a -> P a -> P a # MonadPlus (U1 :: * -> *) Since: base-4.9.0.0 Instance detailsDefined in GHC.Generics Methodsmzero :: U1 a #mplus :: U1 a -> U1 a -> U1 a # (ArrowApply a, ArrowPlus a) => MonadPlus (ArrowMonad a) Since: base-4.6.0.0 Instance detailsDefined in Control.Arrow Methodsmzero :: ArrowMonad a a0 #mplus :: ArrowMonad a a0 -> ArrowMonad a a0 -> ArrowMonad a a0 # MonadPlus (Proxy :: * -> *) Since: base-4.9.0.0 Instance detailsDefined in Data.Proxy Methodsmzero :: Proxy a #mplus :: Proxy a -> Proxy a -> Proxy a # MonadPlus mu => MonadPlus (C mu) # Instance detailsDefined in Control.Monad.Free.Improve Methodsmzero :: C mu a #mplus :: C mu a -> C mu a -> C mu a # MonadPlus f => MonadPlus (Rec1 f) Since: base-4.9.0.0 Instance detailsDefined in GHC.Generics Methodsmzero :: Rec1 f a #mplus :: Rec1 f a -> Rec1 f a -> Rec1 f a # MonadPlus f => MonadPlus (Alt f) Instance detailsDefined in Data.Semigroup.Internal Methodsmzero :: Alt f a #mplus :: Alt f a -> Alt f a -> Alt f a # MonadPlus m => MonadPlus (StateT s m) Instance detailsDefined in Control.Monad.Trans.State.Lazy Methodsmzero :: StateT s m a #mplus :: StateT s m a -> StateT s m a -> StateT s m a # (Functor f, Monad m, MonadPlus m) => MonadPlus (FreeT f m) # Instance detailsDefined in Control.Monad.Free Methodsmzero :: FreeT f m a #mplus :: FreeT f m a -> FreeT f m a -> FreeT f m a # (MonadPlus f, MonadPlus g) => MonadPlus (f :*: g) Since: base-4.9.0.0 Instance detailsDefined in GHC.Generics Methodsmzero :: (f :*: g) a #mplus :: (f :*: g) a -> (f :*: g) a -> (f :*: g) a # MonadPlus f => MonadPlus (M1 i c f) Since: base-4.9.0.0 Instance detailsDefined in GHC.Generics Methodsmzero :: M1 i c f a #mplus :: M1 i c f a -> M1 i c f a -> M1 i c f a # # Free Monads class (Functor f, Monad m) => MonadFree f m where Source # This type class generalizes over encodings of Free Monads. Minimal complete definition Methods Arguments  :: m a -> m (Either a (f (m a))) Opens` a computation and allows to observe the side effects Arguments  :: f (m a) -> m a Wraps a side effect into a monadic computation Instances  Functor f => MonadFree f (Free f) Source # Instance detailsDefined in Control.Monad.Free Methodsfree :: Free f a -> Free f (Either a (f (Free f a))) Source #wrap :: f (Free f a) -> Free f a Source # (Monad m, Functor f) => MonadFree f (C (FreeT f m)) Source # Instance detailsDefined in Control.Monad.Free.Improve Methodsfree :: C (FreeT f m) a -> C (FreeT f m) (Either a (f (C (FreeT f m) a))) Source #wrap :: f (C (FreeT f m) a) -> C (FreeT f m) a Source # Functor f => MonadFree f (C (Free f)) Source # Instance detailsDefined in Control.Monad.Free.Improve Methodsfree :: C (Free f) a -> C (Free f) (Either a (f (C (Free f) a))) Source #wrap :: f (C (Free f) a) -> C (Free f) a Source # (Functor f, Monad m) => MonadFree f (FreeT f m) Source # Instance detailsDefined in Control.Monad.Free Methodsfree :: FreeT f m a -> FreeT f m (Either a (f (FreeT f m a))) Source #wrap :: f (FreeT f m a) -> FreeT f m a Source # data Free f a Source # Constructors  Impure (f (Free f a)) Pure a Instances  Functor f => MonadFree f (Free f) Source # Instance detailsDefined in Control.Monad.Free Methodsfree :: Free f a -> Free f (Either a (f (Free f a))) Source #wrap :: f (Free f a) -> Free f a Source # Functor f => MonadFree f (C (Free f)) Source # Instance detailsDefined in Control.Monad.Free.Improve Methodsfree :: C (Free f) a -> C (Free f) (Either a (f (C (Free f) a))) Source #wrap :: f (C (Free f) a) -> C (Free f) a Source # Functor f => Monad (Free f) Source # Instance detailsDefined in Control.Monad.Free Methods(>>=) :: Free f a -> (a -> Free f b) -> Free f b #(>>) :: Free f a -> Free f b -> Free f b #return :: a -> Free f a #fail :: String -> Free f a # Functor f => Functor (Free f) Source # Instance detailsDefined in Control.Monad.Free Methodsfmap :: (a -> b) -> Free f a -> Free f b #(<$) :: a -> Free f b -> Free f a # Functor f => Applicative (Free f) Source # Instance detailsDefined in Control.Monad.Free Methodspure :: a -> Free f a #(<*>) :: Free f (a -> b) -> Free f a -> Free f b #liftA2 :: (a -> b -> c) -> Free f a -> Free f b -> Free f c #(*>) :: Free f a -> Free f b -> Free f b #(<*) :: Free f a -> Free f b -> Free f a # (Functor f, Foldable f) => Foldable (Free f) Source # Instance detailsDefined in Control.Monad.Free Methodsfold :: 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 #toList :: Free f a -> [a] #null :: Free f a -> Bool #length :: Free f a -> Int #elem :: Eq a => a -> Free f a -> Bool #maximum :: Ord a => Free f a -> a #minimum :: Ord a => Free f a -> a #sum :: Num a => Free f a -> a #product :: Num a => Free f a -> a # Traversable f => Traversable (Free f) Source # Instance detailsDefined in Control.Monad.Free Methodstraverse :: Applicative f0 => (a -> f0 b) -> Free f a -> f0 (Free f b) #sequenceA :: Applicative f0 => Free f (f0 a) -> f0 (Free f a) #mapM :: Monad m => (a -> m b) -> Free f a -> m (Free f b) #sequence :: Monad m => Free f (m a) -> m (Free f a) # Eq1 f => Eq1 (Free f) Source # Instance detailsDefined in Control.Monad.Free MethodsliftEq :: (a -> b -> Bool) -> Free f a -> Free f b -> Bool # Ord1 f => Ord1 (Free f) Source # Instance detailsDefined in Control.Monad.Free MethodsliftCompare :: (a -> b -> Ordering) -> Free f a -> Free f b -> Ordering # (Eq a, Eq1 f) => Eq (Free f a) Source # Instance detailsDefined in Control.Monad.Free Methods(==) :: Free f a -> Free f a -> Bool #(/=) :: Free f a -> Free f a -> Bool # (Ord a, Ord1 f) => Ord (Free f a) Source # Instance detailsDefined in Control.Monad.Free Methodscompare :: Free f a -> Free f a -> Ordering #(<) :: Free f a -> Free f a -> Bool #(<=) :: Free f a -> Free f a -> Bool #(>) :: Free f a -> Free f a -> Bool #(>=) :: Free f a -> Free f a -> Bool #max :: Free f a -> Free f a -> Free f a #min :: Free f a -> Free f a -> Free f a # (Show a, Show1 f) => Show (Free f a) Source # Instance detailsDefined in Control.Monad.Free MethodsshowsPrec :: Int -> Free f a -> ShowS #show :: Free f a -> String #showList :: [Free f a] -> ShowS # Generic (Free f a) Source # Instance detailsDefined in Control.Monad.Free Associated Typestype Rep (Free f a) :: * -> * # Methodsfrom :: Free f a -> Rep (Free f a) x #to :: Rep (Free f a) x -> Free f a # type Rep (Free f a) Source # Instance detailsDefined in Control.Monad.Free type Rep (Free f a) = D1 (MetaData "Free" "Control.Monad.Free" "control-monad-free-0.6.2-D8gRCj9jdnL78y3kztZ3ka" 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)))

isPure :: Free f a -> Bool Source #

foldFree :: Functor f => (a -> b) -> (f b -> b) -> Free f a -> b Source #

evalFree :: (a -> b) -> (f (Free f a) -> b) -> Free f a -> b Source #

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 #

foldFreeM :: (Traversable f, Monad m) => (a -> m b) -> (f b -> m b) -> Free f a -> m b Source #

induce :: (Functor f, Monad m) => (forall a. f a -> m a) -> Free f a -> m a Source #

newtype FreeT f m a Source #

Constructors

 FreeT FieldsunFreeT :: m (Either a (f (FreeT f m a)))
Instances

foldFreeT :: (Traversable f, Monad m) => (a -> m b) -> (f b -> m b) -> FreeT f m a -> m b 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 #