| Safe Haskell | Safe | 
|---|---|
| Language | Haskell2010 | 
Monad.Trans
Contents
Synopsis
- class MonadTrans (t :: (* -> *) -> * -> *) where
 - data FreeF (f :: * -> *) a b
 - liftF :: (Functor f, MonadFree f m) => f a -> m a
 - type Free (f :: * -> *) = FreeT f Identity
 - free :: FreeF f a (Free f a) -> Free f a
 - runFree :: Free f a -> FreeF f a (Free f a)
 - retract :: Monad f => Free f a -> f a
 - iter :: Functor f => (f a -> a) -> Free f a -> a
 - iterM :: (Functor f, Monad m) => (f (m a) -> m a) -> Free f a -> m a
 - newtype FreeT (f :: * -> *) (m :: * -> *) a = FreeT {}
 - iterT :: (Functor f, Monad m) => (f (m a) -> m a) -> FreeT f m a -> m a
 - iterTM :: (Functor f, Monad m, MonadTrans t, Monad (t m)) => (f (t m a) -> t m a) -> FreeT f m a -> t m a
 - hoistFreeT :: (Monad m, Functor f) => (forall a. m a -> n a) -> FreeT f m b -> FreeT f n b
 - foldFreeT :: (MonadTrans t, Monad (t m), Monad m) => (forall (n :: * -> *) x. Monad n => f x -> t n x) -> FreeT f m a -> t m a
 - transFreeT :: (Monad m, Functor g) => (forall a. f a -> g a) -> FreeT f m b -> FreeT g m b
 - joinFreeT :: (Monad m, Traversable f) => FreeT f m a -> m (Free f a)
 - retractT :: (MonadTrans t, Monad (t m), Monad m) => FreeT (t m) m a -> t m a
 - class Monad m => MonadFree (f :: * -> *) (m :: * -> *) | m -> f where
 
MonadTrans
class MonadTrans (t :: (* -> *) -> * -> *) where #
The class of monad transformers.  Instances should satisfy the
 following laws, which state that lift is a monad transformation:
Minimal complete definition
Methods
lift :: Monad m => m a -> t m a #
Lift a computation from the argument monad to the constructed monad.
Instances
Free monad transformer
data FreeF (f :: * -> *) a b #
The base functor for a free monad.
Instances
| Traversable f => Bitraversable (FreeF f) | |
Defined in Control.Monad.Trans.Free Methods bitraverse :: Applicative f0 => (a -> f0 c) -> (b -> f0 d) -> FreeF f a b -> f0 (FreeF f c d) #  | |
| Foldable f => Bifoldable (FreeF f) | |
| Functor f => Bifunctor (FreeF f) | |
| Eq1 f => Eq2 (FreeF f) | |
| Ord1 f => Ord2 (FreeF f) | |
Defined in Control.Monad.Trans.Free  | |
| Read1 f => Read2 (FreeF f) | |
Defined in Control.Monad.Trans.Free Methods liftReadsPrec2 :: (Int -> ReadS a) -> ReadS [a] -> (Int -> ReadS b) -> ReadS [b] -> Int -> ReadS (FreeF f a b) # liftReadList2 :: (Int -> ReadS a) -> ReadS [a] -> (Int -> ReadS b) -> ReadS [b] -> ReadS [FreeF f a b] # liftReadPrec2 :: ReadPrec a -> ReadPrec [a] -> ReadPrec b -> ReadPrec [b] -> ReadPrec (FreeF f a b) # liftReadListPrec2 :: ReadPrec a -> ReadPrec [a] -> ReadPrec b -> ReadPrec [b] -> ReadPrec [FreeF f a b] #  | |
| Show1 f => Show2 (FreeF f) | |
| Generic1 (FreeF f a :: * -> *) | |
| Functor f => Functor (FreeF f a) | |
| Foldable f => Foldable (FreeF f a) | |
Defined in Control.Monad.Trans.Free Methods fold :: Monoid m => FreeF f a m -> m # foldMap :: Monoid m => (a0 -> m) -> FreeF f a a0 -> m # foldr :: (a0 -> b -> b) -> b -> FreeF f a a0 -> b # foldr' :: (a0 -> b -> b) -> b -> FreeF f a a0 -> b # foldl :: (b -> a0 -> b) -> b -> FreeF f a a0 -> b # foldl' :: (b -> a0 -> b) -> b -> FreeF f a a0 -> b # foldr1 :: (a0 -> a0 -> a0) -> FreeF f a a0 -> a0 # foldl1 :: (a0 -> a0 -> a0) -> FreeF f a a0 -> a0 # toList :: FreeF f a a0 -> [a0] # null :: FreeF f a a0 -> Bool # length :: FreeF f a a0 -> Int # elem :: Eq a0 => a0 -> FreeF f a a0 -> Bool # maximum :: Ord a0 => FreeF f a a0 -> a0 # minimum :: Ord a0 => FreeF f a a0 -> a0 #  | |
| Traversable f => Traversable (FreeF f a) | |
Defined in Control.Monad.Trans.Free  | |
| (Eq1 f, Eq a) => Eq1 (FreeF f a) | |
| (Ord1 f, Ord a) => Ord1 (FreeF f a) | |
Defined in Control.Monad.Trans.Free  | |
| (Read1 f, Read a) => Read1 (FreeF f a) | |
Defined in Control.Monad.Trans.Free Methods liftReadsPrec :: (Int -> ReadS a0) -> ReadS [a0] -> Int -> ReadS (FreeF f a a0) # liftReadList :: (Int -> ReadS a0) -> ReadS [a0] -> ReadS [FreeF f a a0] # liftReadPrec :: ReadPrec a0 -> ReadPrec [a0] -> ReadPrec (FreeF f a a0) # liftReadListPrec :: ReadPrec a0 -> ReadPrec [a0] -> ReadPrec [FreeF f a a0] #  | |
| (Show1 f, Show a) => Show1 (FreeF f a) | |
| (Eq a, Eq (f b)) => Eq (FreeF f a b) | |
| (Ord a, Ord (f b)) => Ord (FreeF f a b) | |
Defined in Control.Monad.Trans.Free  | |
| (Read a, Read (f b)) => Read (FreeF f a b) | |
| (Show a, Show (f b)) => Show (FreeF f a b) | |
| Generic (FreeF f a b) | |
| type Rep1 (FreeF f a :: * -> *) | |
Defined in Control.Monad.Trans.Free type Rep1 (FreeF f a :: * -> *) = D1 (MetaData "FreeF" "Control.Monad.Trans.Free" "free-5.1-9P5wnlKdQjU2MUQcy2f6zg" False) (C1 (MetaCons "Pure" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a)) :+: C1 (MetaCons "Free" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec1 f)))  | |
| type Rep (FreeF f a b) | |
Defined in Control.Monad.Trans.Free type Rep (FreeF f a b) = D1 (MetaData "FreeF" "Control.Monad.Trans.Free" "free-5.1-9P5wnlKdQjU2MUQcy2f6zg" False) (C1 (MetaCons "Pure" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a)) :+: C1 (MetaCons "Free" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (f b))))  | |
liftF :: (Functor f, MonadFree f m) => f a -> m a #
A version of lift that can be used with just a Functor for f.
newtype FreeT (f :: * -> *) (m :: * -> *) a #
The "free monad transformer" for a functor f
Instances
iterT :: (Functor f, Monad m) => (f (m a) -> m a) -> FreeT f m a -> m a #
Tear down a free monad transformer using iteration.
iterTM :: (Functor f, Monad m, MonadTrans t, Monad (t m)) => (f (t m a) -> t m a) -> FreeT f m a -> t m a #
Tear down a free monad transformer using iteration over a transformer.
foldFreeT :: (MonadTrans t, Monad (t m), Monad m) => (forall (n :: * -> *) x. Monad n => f x -> t n x) -> FreeT f m a -> t m a #
The very definition of a free monad transformer is that given a natural transformation you get a monad transformer homomorphism.
joinFreeT :: (Monad m, Traversable f) => FreeT f m a -> m (Free f a) #
Pull out and join m layers of .FreeT f m a
retractT :: (MonadTrans t, Monad (t m), Monad m) => FreeT (t m) m a -> t m a #
Tear down a free monad transformer using Monad instance for t m.
class Monad m => MonadFree (f :: * -> *) (m :: * -> *) | m -> f where #
Monads provide substitution (fmap) and renormalization (join):
m>>=f =join(fmapf m)
A free Monad is one that does no work during the normalization step beyond simply grafting the two monadic values together.
[] is not a free Monad (in this sense) because  smashes the lists flat.join [[a]]
On the other hand, consider:
data Tree a = Bin (Tree a) (Tree a) | Tip a
instanceMonadTree wherereturn= Tip Tip a>>=f = f a Bin l r>>=f = Bin (l>>=f) (r>>=f)
This Monad is the free Monad of Pair:
data Pair a = Pair a a
And we could make an instance of MonadFree for it directly:
instanceMonadFreePair Tree wherewrap(Pair l r) = Bin l r
Or we could choose to program with  instead of Free PairTree
 and thereby avoid having to define our own Monad instance.
Moreover, Control.Monad.Free.Church provides a MonadFree
 instance that can improve the asymptotic complexity of code that
 constructs free monads by effectively reassociating the use of
 (>>=). You may also want to take a look at the kan-extensions
 package (http://hackage.haskell.org/package/kan-extensions).
See Free for a more formal definition of the free Monad
 for a Functor.