-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Monads for free -- -- Free monads are useful for many tree-like structures and domain -- specific languages. -- -- A Monad n is a free Monad for f if -- every Monad homomorphism from n to another monad -- m is equivalent to a natural transformation from f -- to m. -- -- Cofree comonads provide convenient ways to talk about branching -- streams and rose-trees, and can be used to annotate syntax trees. -- -- A Comonad v is a cofree Comonad for f -- if every Comonad homomorphism another comonad w to -- v is equivalent to a natural transformation from w -- to f. @package free @version 3.3 module Control.Comonad.Cofree.Class -- | Allows you to peel a layer off a cofree comonad. class (Functor f, Comonad w) => ComonadCofree f w | w -> f unwrap :: ComonadCofree f w => w a -> f (w a) instance (ComonadCofree f w, Semigroup m, Monoid m) => ComonadCofree f (TracedT m w) instance ComonadCofree f w => ComonadCofree f (StoreT s w) instance ComonadCofree f w => ComonadCofree f (EnvT e w) instance ComonadCofree f w => ComonadCofree f (IdentityT w) -- | The cofree comonad transformer module Control.Comonad.Trans.Cofree -- | This is a cofree comonad of some functor f, with a comonad -- w threaded through it at each level. newtype CofreeT f w a CofreeT :: w (CofreeF f a (CofreeT f w a)) -> CofreeT f w a runCofreeT :: CofreeT f w a -> w (CofreeF f a (CofreeT f w a)) -- | This is the base functor of the cofree comonad transformer. data CofreeF f a b (:<) :: a -> f b -> CofreeF f a b -- | Allows you to peel a layer off a cofree comonad. class (Functor f, Comonad w) => ComonadCofree f w | w -> f unwrap :: ComonadCofree f w => w a -> f (w a) -- | Extract the head of the base functor headF :: CofreeF f a b -> a -- | Extract the tails of the base functor tailF :: CofreeF f a b -> f b instance (Eq a, Eq (f b)) => Eq (CofreeF f a b) instance (Ord a, Ord (f b)) => Ord (CofreeF f a b) instance (Show a, Show (f b)) => Show (CofreeF f a b) instance (Read a, Read (f b)) => Read (CofreeF f a b) instance (Typeable1 f, Typeable1 w, Typeable a, Data (w (CofreeF f a (CofreeT f w a))), Data a) => Data (CofreeT f w a) instance (Typeable1 f, Typeable a, Typeable b, Data a, Data (f b), Data b) => Data (CofreeF f a b) instance (Typeable1 f, Typeable1 w) => Typeable1 (CofreeT f w) instance Typeable1 f => Typeable2 (CofreeF f) instance Ord (w (CofreeF f a (CofreeT f w a))) => Ord (CofreeT f w a) instance Eq (w (CofreeF f a (CofreeT f w a))) => Eq (CofreeT f w a) instance Read (w (CofreeF f a (CofreeT f w a))) => Read (CofreeT f w a) instance Show (w (CofreeF f a (CofreeT f w a))) => Show (CofreeT f w a) instance (Functor f, Comonad w) => ComonadCofree f (CofreeT f w) instance Functor f => ComonadTrans (CofreeT f) instance (Traversable f, Traversable w) => Traversable (CofreeT f w) instance (Foldable f, Foldable w) => Foldable (CofreeT f w) instance (Functor f, Comonad w) => Comonad (CofreeT f w) instance (Functor f, Functor w) => Functor (CofreeT f w) instance Traversable f => Bitraversable (CofreeF f) instance Foldable f => Bifoldable (CofreeF f) instance Functor f => Bifunctor (CofreeF f) instance Traversable f => Traversable (CofreeF f a) instance Foldable f => Foldable (CofreeF f a) instance Functor f => Functor (CofreeF f a) -- | Cofree comonads module Control.Comonad.Cofree -- | The Cofree Comonad of a functor f. -- -- Formally -- -- A Comonad v is a cofree Comonad for f -- if every comonad homomorphism another comonad w to v -- is equivalent to a natural transformation from w to -- f. -- -- A cofree functor is right adjoint to a forgetful functor. -- -- Cofree is a functor from the category of functors to the category of -- comonads that is right adjoint to the forgetful functor from the -- category of comonads to the category of functors that forgets how to -- extract and duplicate, leaving you with only a -- Functor. -- -- In practice, cofree comonads are quite useful for annotating syntax -- trees, or talking about streams. -- -- A number of common comonads arise directly as cofree comonads. -- -- For instance, -- -- data Cofree f a (:<) :: a -> f (Cofree f a) -> Cofree f a -- | Allows you to peel a layer off a cofree comonad. class (Functor f, Comonad w) => ComonadCofree f w | w -> f unwrap :: ComonadCofree f w => w a -> f (w a) -- |
--   lower . section = id
--   
section :: Comonad f => f a -> Cofree f a -- | Use coiteration to generate a cofree comonad from a seed. -- --
--   coiter f = unfold (id &&& f)
--   
coiter :: Functor f => (a -> f a) -> a -> Cofree f a -- | Unfold a cofree comonad from a seed. unfold :: Functor f => (b -> (a, f b)) -> b -> Cofree f a -- | This is a lens that can be used to read or write from the target of -- extract. -- -- Using (^.) from the lens package: -- --
--   foo ^. _extract == extract foo
--   
-- -- For more on lenses see the lens package on hackage -- --
--   _extract :: Lens' (Cofree g a) a
--   
_extract :: Functor f => (a -> f a) -> Cofree g a -> f (Cofree g a) -- | This is a lens that can be used to read or write to the tails of a -- Cofree Comonad. -- -- Using (^.) from the lens package: -- --
--   foo ^. _unwrap == unwrap foo
--   
-- -- For more on lenses see the lens package on hackage -- --
--   _unwrap :: Lens' (Cofree g a) (g (Cofree g a))
--   
_unwrap :: Functor f => (g (Cofree g a) -> f (g (Cofree g a))) -> Cofree g a -> f (Cofree g a) -- | Construct a Lens into a Cofree f given a list -- of lenses into the base functor. -- -- For more on lenses see the lens package on hackage. -- --
--   telescoped :: Functor g => [Lens' (Cofree g a) (g (Cofree g a))] -> Lens' (Cofree g a) a
--   
telescoped :: (Functor f, Functor g) => [(Cofree g a -> f (Cofree g a)) -> g (Cofree g a) -> f (g (Cofree g a))] -> (a -> f a) -> Cofree g a -> f (Cofree g a) instance ComonadTraced m w => ComonadTraced m (Cofree w) instance ComonadStore s w => ComonadStore s (Cofree w) instance ComonadEnv e w => ComonadEnv e (Cofree w) instance (Typeable1 f, Data (f (Cofree f a)), Data a) => Data (Cofree f a) instance (Typeable1 f, Typeable a) => Typeable (Cofree f a) instance Typeable1 f => Typeable1 (Cofree f) instance Traversable1 f => Traversable1 (Cofree f) instance Traversable f => Traversable (Cofree f) instance Foldable1 f => Foldable1 (Cofree f) instance Foldable f => Foldable (Cofree f) instance (Ord (f (Cofree f a)), Ord a) => Ord (Cofree f a) instance (Eq (f (Cofree f a)), Eq a) => Eq (Cofree f a) instance (Read (f (Cofree f a)), Read a) => Read (Cofree f a) instance (Show (f (Cofree f a)), Show a) => Show (Cofree f a) instance Applicative f => Applicative (Cofree f) instance ComonadApply f => ComonadApply (Cofree f) instance Apply f => Apply (Cofree f) instance Alternative f => Monad (Cofree f) instance ComonadTrans Cofree instance Functor f => Comonad (Cofree f) instance Functor f => Extend (Cofree f) instance Functor f => Functor (Cofree f) instance Distributive f => Distributive (Cofree f) instance Functor f => ComonadCofree f (Cofree f) -- | Monads for free. module Control.Monad.Free.Class -- | Monads provide substitution (fmap) and renormalization -- (join): -- --
--   m >>= f = join . fmap f 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 -- join [[a]] smashes the lists flat. -- -- On the other hand, consider: -- --
--   data Tree a = Bin (Tree a) (Tree a) | Tip a
--   
-- --
--   instance Monad Tree where
--     return = 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: -- --
--   instance MonadFree Pair Tree where
--      wrap (Pair l r) = Bin l r
--   
-- -- Or we could choose to program with Free Pair instead -- of Tree and thereby avoid having to define our own -- Monad instance. -- -- Moreover, the kan-extensions package provides -- MonadFree instances that can improve the asymptotic -- complexity of code that constructors free monads by effectively -- reassociating the use of (>>=). -- -- See Free for a more formal definition of the free Monad -- for a Functor. class Monad m => MonadFree f m | m -> f wrap :: MonadFree f m => f (m a) -> m a instance (Functor f, MonadFree f m, Error e) => MonadFree f (ErrorT e m) instance (Functor f, MonadFree f m) => MonadFree f (ListT m) instance (Functor f, MonadFree f m) => MonadFree f (IdentityT m) instance (Functor f, MonadFree f m) => MonadFree f (MaybeT m) instance (Functor f, MonadFree f m, Monoid w) => MonadFree f (RWST r w s m) instance (Functor f, MonadFree f m, Monoid w) => MonadFree f (RWST r w s m) instance (Functor f, MonadFree f m, Monoid w) => MonadFree f (WriterT w m) instance (Functor f, MonadFree f m, Monoid w) => MonadFree f (WriterT w m) instance (Functor f, MonadFree f m) => MonadFree f (StateT s m) instance (Functor f, MonadFree f m) => MonadFree f (StateT s m) instance (Functor f, MonadFree f m) => MonadFree f (ReaderT e m) -- | The free monad transformer module Control.Monad.Trans.Free -- | The base functor for a free monad. data FreeF f a b Pure :: a -> FreeF f a b Free :: (f b) -> FreeF f a b -- | The "free monad transformer" for a functor f. newtype FreeT f m a FreeT :: m (FreeF f a (FreeT f m a)) -> FreeT f m a runFreeT :: FreeT f m a -> m (FreeF f a (FreeT f m a)) -- | Monads provide substitution (fmap) and renormalization -- (join): -- --
--   m >>= f = join . fmap f 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 -- join [[a]] smashes the lists flat. -- -- On the other hand, consider: -- --
--   data Tree a = Bin (Tree a) (Tree a) | Tip a
--   
-- --
--   instance Monad Tree where
--     return = 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: -- --
--   instance MonadFree Pair Tree where
--      wrap (Pair l r) = Bin l r
--   
-- -- Or we could choose to program with Free Pair instead -- of Tree and thereby avoid having to define our own -- Monad instance. -- -- Moreover, the kan-extensions package provides -- MonadFree instances that can improve the asymptotic -- complexity of code that constructors free monads by effectively -- reassociating the use of (>>=). -- -- See Free for a more formal definition of the free Monad -- for a Functor. class Monad m => MonadFree f m | m -> f wrap :: MonadFree f m => f (m a) -> m a -- | FreeT is a functor from the category of functors to the category of -- monads. -- -- This provides the mapping. liftF :: (Functor f, Monad m) => f a -> FreeT f m a -- | Lift a monad homomorphism from m to n into a monad -- homomorphism from FreeT f m to FreeT f -- n -- --
--   hoistFreeT :: (Monad m, Functor f) => (m ~> n) -> FreeT f m ~> FreeT f n
--   
hoistFreeT :: (Monad m, Functor f) => (forall a. m a -> n a) -> FreeT f m b -> FreeT f n b -- | Lift a natural transformation from f to g into a -- monad homomorphism from FreeT f m to FreeT -- g n transFreeT :: (Monad m, Functor g) => (forall a. f a -> g a) -> FreeT f m b -> FreeT g m b instance (Eq a, Eq (f b)) => Eq (FreeF f a b) instance (Ord a, Ord (f b)) => Ord (FreeF f a b) instance (Show a, Show (f b)) => Show (FreeF f a b) instance (Read a, Read (f b)) => Read (FreeF f a b) instance (Typeable1 f, Typeable1 w, Typeable a, Data (w (FreeF f a (FreeT f w a))), Data a) => Data (FreeT f w a) instance (Typeable1 f, Typeable a, Typeable b, Data a, Data (f b), Data b) => Data (FreeF f a b) instance (Typeable1 f, Typeable1 w) => Typeable1 (FreeT f w) instance Typeable1 f => Typeable2 (FreeF f) instance (Monad m, Traversable m, Traversable f) => Traversable (FreeT f m) instance (Foldable m, Foldable f) => Foldable (FreeT f m) instance (Functor f, Monad m) => MonadFree f (FreeT f m) instance (Functor f, MonadPlus m) => MonadPlus (FreeT f m) instance (Functor f, MonadPlus m) => Alternative (FreeT f m) instance (Functor f, MonadIO m) => MonadIO (FreeT f m) instance MonadTrans (FreeT f) instance (Functor f, Monad m) => Monad (FreeT f m) instance (Functor f, Monad m) => Applicative (FreeT f m) instance (Functor f, Monad m) => Functor (FreeT f m) instance Read (m (FreeF f a (FreeT f m a))) => Read (FreeT f m a) instance Show (m (FreeF f a (FreeT f m a))) => Show (FreeT f m a) instance Ord (m (FreeF f a (FreeT f m a))) => Ord (FreeT f m a) instance Eq (m (FreeF f a (FreeT f m a))) => Eq (FreeT f m a) instance Traversable f => Bitraversable (FreeF f) instance Foldable f => Bifoldable (FreeF f) instance Functor f => Bifunctor (FreeF f) instance Traversable f => Traversable (FreeF f a) instance Foldable f => Foldable (FreeF f a) instance Functor f => Functor (FreeF f a) -- | left-distributive MonadPlus for free. module Control.MonadPlus.Free -- | Monads provide substitution (fmap) and renormalization -- (join): -- --
--   m >>= f = join . fmap f 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 -- join [[a]] smashes the lists flat. -- -- On the other hand, consider: -- --
--   data Tree a = Bin (Tree a) (Tree a) | Tip a
--   
-- --
--   instance Monad Tree where
--     return = 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: -- --
--   instance MonadFree Pair Tree where
--      wrap (Pair l r) = Bin l r
--   
-- -- Or we could choose to program with Free Pair instead -- of Tree and thereby avoid having to define our own -- Monad instance. -- -- Moreover, the kan-extensions package provides -- MonadFree instances that can improve the asymptotic -- complexity of code that constructors free monads by effectively -- reassociating the use of (>>=). -- -- See Free for a more formal definition of the free Monad -- for a Functor. class Monad m => MonadFree f m | m -> f wrap :: MonadFree f m => f (m a) -> m a -- | The Free MonadPlus for a Functor f. -- -- Formally -- -- A MonadPlus n is a free MonadPlus for -- f if every monadplus homomorphism from n to another -- MonadPlus m is equivalent to a natural transformation from -- f to m. -- -- We model this internally as if left-distribution holds. -- data Free f a Pure :: a -> Free f a Free :: (f (Free f a)) -> Free f a Plus :: [Free f a] -> Free f a -- | retract is the left inverse of lift and liftF -- --
--   retract . lift = id
--   retract . liftF = id
--   
retract :: MonadPlus f => Free f a -> f a -- | A version of lift that can be used with just a Functor -- for f. liftF :: Functor f => f a -> Free f a -- | Tear down a Free Monad using iteration. iter :: Functor f => (f a -> a) -> ([a] -> a) -> Free f a -> a -- | Lift a natural transformation from f to g into a -- natural transformation from FreeT f to -- FreeT g. hoistFree :: Functor g => (forall a. f a -> g a) -> Free f b -> Free g b instance (Typeable1 f, Typeable a, Data a, Data (f (Free f a))) => Data (Free f a) instance Typeable1 f => Typeable1 (Free f) instance Functor f => MonadFree f (Free f) instance (Functor m, MonadPlus m, MonadCont m) => MonadCont (Free m) instance (Functor m, MonadPlus m, MonadError e m) => MonadError e (Free m) instance (Functor m, MonadState s m) => MonadState s (Free m) instance (Functor m, MonadPlus m, MonadReader e m) => MonadReader e (Free m) instance (Functor m, MonadPlus m, MonadWriter e m) => MonadWriter e (Free m) instance Traversable f => Traversable (Free f) instance Foldable f => Foldable (Free f) instance MonadTrans Free instance Functor f => Monoid (Free f a) instance Functor f => Semigroup (Free f a) instance Functor f => MonadPlus (Free f) instance Functor f => Alternative (Free f) instance Functor f => Monad (Free f) instance Functor f => Bind (Free f) instance Functor f => Applicative (Free f) instance Functor f => Apply (Free f) instance Functor f => Functor (Free f) instance (Read (f (Free f a)), Read a) => Read (Free f a) instance (Show (f (Free f a)), Show a) => Show (Free f a) instance (Ord (f (Free f a)), Ord a) => Ord (Free f a) instance (Eq (f (Free f a)), Eq a) => Eq (Free f a) -- | Monads for free module Control.Monad.Free -- | Monads provide substitution (fmap) and renormalization -- (join): -- --
--   m >>= f = join . fmap f 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 -- join [[a]] smashes the lists flat. -- -- On the other hand, consider: -- --
--   data Tree a = Bin (Tree a) (Tree a) | Tip a
--   
-- --
--   instance Monad Tree where
--     return = 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: -- --
--   instance MonadFree Pair Tree where
--      wrap (Pair l r) = Bin l r
--   
-- -- Or we could choose to program with Free Pair instead -- of Tree and thereby avoid having to define our own -- Monad instance. -- -- Moreover, the kan-extensions package provides -- MonadFree instances that can improve the asymptotic -- complexity of code that constructors free monads by effectively -- reassociating the use of (>>=). -- -- See Free for a more formal definition of the free Monad -- for a Functor. class Monad m => MonadFree f m | m -> f wrap :: MonadFree f m => f (m a) -> m a -- | The Free Monad for a Functor f. -- -- Formally -- -- A Monad n is a free Monad for f if -- every monad homomorphism from n to another monad m -- is equivalent to a natural transformation from f to -- m. -- -- Why Free? -- -- Every "free" functor is left adjoint to some "forgetful" functor. -- -- If we define a forgetful functor U from the category of -- monads to the category of functors that just forgets the Monad, -- leaving only the Functor. i.e. -- --
--   U (M,return,join) = M
--   
-- -- then Free is the left adjoint to U. -- -- Being Free being left adjoint to U means that there is -- an isomorphism between -- -- Free f -> m in the category of monads and f -- -> U m in the category of functors. -- -- Morphisms in the category of monads are Monad homomorphisms -- (natural transformations that respect return and join). -- -- Morphisms in the category of functors are Functor homomorphisms -- (natural transformations). -- -- Given this isomorphism, every monad homomorphism from Free -- f to m is equivalent to a natural transformation from -- f to m -- -- Showing that this isomorphism holds is left as an exercise. -- -- In practice, you can just view a Free f a as many -- layers of f wrapped around values of type a, where -- (>>=) performs substitution and grafts new -- layers of f in for each of the free variables. -- -- This can be very useful for modeling domain specific languages, trees, -- or other constructs. -- -- This instance of MonadFree is fairly naive about the encoding. -- For more efficient free monad implementations that require additional -- extensions and thus aren't included here, you may want to look at the -- kan-extensions package. -- -- A number of common monads arise as free monads, -- -- data Free f a Pure :: a -> Free f a Free :: (f (Free f a)) -> Free f a -- | retract is the left inverse of lift and liftF -- --
--   retract . lift = id
--   retract . liftF = id
--   
retract :: Monad f => Free f a -> f a -- | A version of lift that can be used with just a Functor -- for f. liftF :: Functor f => f a -> Free f a -- | Tear down a Free Monad using iteration. iter :: Functor f => (f a -> a) -> Free f a -> a -- | Lift a natural transformation from f to g into a -- natural transformation from FreeT f to -- FreeT g. hoistFree :: Functor g => (forall a. f a -> g a) -> Free f b -> Free g b instance (Typeable1 f, Typeable a, Data a, Data (f (Free f a))) => Data (Free f a) instance Typeable1 f => Typeable1 (Free f) instance Functor f => MonadFree f (Free f) instance (Functor m, MonadCont m) => MonadCont (Free m) instance (Functor m, MonadError e m) => MonadError e (Free m) instance (Functor m, MonadState s m) => MonadState s (Free m) instance (Functor m, MonadReader e m) => MonadReader e (Free m) instance (Functor m, MonadWriter e m) => MonadWriter e (Free m) instance Traversable1 f => Traversable1 (Free f) instance Traversable f => Traversable (Free f) instance Foldable1 f => Foldable1 (Free f) instance Foldable f => Foldable (Free f) instance MonadTrans Free instance (Functor v, MonadPlus v) => MonadPlus (Free v) instance Alternative v => Alternative (Free v) instance Functor f => Monad (Free f) instance Functor f => Bind (Free f) instance Functor f => Applicative (Free f) instance Functor f => Apply (Free f) instance Functor f => Functor (Free f) instance (Read (f (Free f a)), Read a) => Read (Free f a) instance (Show (f (Free f a)), Show a) => Show (Free f a) instance (Ord (f (Free f a)), Ord a) => Ord (Free f a) instance (Eq (f (Free f a)), Eq a) => Eq (Free f a) -- | "Free Monads for Less" -- -- This is based on the "Free Monads for Less" series of articles: -- -- http://comonad.com/reader/2011/free-monads-for-less/ -- http://comonad.com/reader/2011/free-monads-for-less-2/ module Control.Monad.Free.Church -- | The Church-encoded free monad for a functor f. -- -- It is asymptotically more efficient to use (>>=) -- for F than it is to (>>=) with Free. -- -- http://comonad.com/reader/2011/free-monads-for-less-2/ newtype F f a F :: (forall r. (a -> r) -> (f r -> r) -> r) -> F f a runF :: F f a -> forall r. (a -> r) -> (f r -> r) -> r -- | Improve the asymptotic performance of code that builds a free monad -- with only binds and returns by using F behind the scenes. -- -- This is based on the "Free Monads for Less" series of articles by -- Edward Kmett: -- -- http://comonad.com/reader/2011/free-monads-for-less/ -- http://comonad.com/reader/2011/free-monads-for-less-2/ -- -- and "Asymptotic Improvement of Computations over Free Monads" by Janis -- Voightländer: -- -- http://www.iai.uni-bonn.de/~jv/mpc08.pdf improve :: Functor f => (forall m. MonadFree f m => m a) -> Free f a -- | Convert to another free monad representation. fromF :: MonadFree f m => F f a -> m a -- | Generate a Church-encoded free monad from a Free monad. toF :: Functor f => Free f a -> F f a -- | A version of lift that can be used with just a Functor -- for f. liftF :: Functor f => f a -> F f a -- | retract is the left inverse of lift and liftF -- --
--   retract . lift = id
--   retract . liftF = id
--   
retract :: Monad m => F m a -> m a instance MonadCont m => MonadCont (F m) instance MonadWriter w m => MonadWriter w (F m) instance MonadReader e m => MonadReader e (F m) instance MonadState s m => MonadState s (F m) instance Functor f => MonadFree f (F f) instance MonadTrans F instance MonadPlus f => MonadPlus (F f) instance Monad (F f) instance Bind (F f) instance Alternative f => Alternative (F f) instance Applicative (F f) instance Apply (F f) instance Functor (F f) -- | Left distributive Alternative functors for free, based on a -- design by Stijn van Drongelen. module Control.Alternative.Free -- | The free Applicative for a Functor f. data Alt f a Pure :: a -> Alt f a Ap :: f a -> Alt f (a -> b) -> Alt f b Alt :: [Alt f a] -> Alt f a -- | Given a natural transformation from f to g, this -- gives a canonical monoidal natural transformation from Ap -- f to g. runAlt :: Alternative g => (forall x. f x -> g x) -> Alt f a -> g a -- | A version of lift that can be used with just a Functor -- for f. liftAlt :: f a -> Alt f a -- | Given a natural transformation from f to g this -- gives a monoidal natural transformation from Ap f to Ap -- g. hoistAlt :: (forall a. f a -> g a) -> Alt f b -> Alt g b instance Typeable1 f => Typeable1 (Alt f) instance Monoid (Alt f a) instance Semigroup (Alt f a) instance Alternative (Alt f) instance Applicative (Alt f) instance Apply (Alt f) instance Functor (Alt f) -- | Applicative functors for free module Control.Applicative.Free -- | The free Applicative for a Functor f. data Ap f a Pure :: a -> Ap f a Ap :: f a -> Ap f (a -> b) -> Ap f b -- | Given a natural transformation from f to g, this -- gives a canonical monoidal natural transformation from Ap -- f to g. runAp :: Applicative g => (forall x. f x -> g x) -> Ap f a -> g a -- | A version of lift that can be used with just a Functor -- for f. liftAp :: f a -> Ap f a -- | Given a natural transformation from f to g this -- gives a monoidal natural transformation from Ap f to Ap -- g. hoistAp :: (forall a. f a -> g a) -> Ap f b -> Ap g b instance Typeable1 f => Typeable1 (Ap f) instance Applicative (Ap f) instance Apply (Ap f) instance Functor (Ap f)