for-free-0.1: Functor, Monad, MonadPlus, etc for free

Safe HaskellSafe-Infered

Control.ForFree

Contents

Synopsis

Plus

class Plus f whereSource

zero and plus should form a monoid.

Methods

zero :: f xSource

plus :: f x -> f x -> f xSource

Instances

Plus [] 
Plus Endo 
Plus Maybe 
Plus Seq 
Plus IntMap 
Plus Comparison 
Monoid x => Plus (Const x) 
Ord k => Plus (Map k) 
Monoid x => Plus (Op x) 
(Functor m, Monad m) => Plus (MaybeT m) 
Comonad w => Plus (CodensityAsk w) 
Plus f => Plus (Codensity f) 
Plus f => Plus (Free f) 
Plus f => Plus (Yoneda f) 
(ArrowZero a, ArrowPlus a) => Plus (WrappedArrow a b) 
Plus f => Plus (WriterT x f) 
MonadPlus m => Plus (StateT s m) 
Plus f => Plus (ReaderT x f) 
Comonad w => Plus (CodensityAskT w f) 
Plus m => Plus (FreeT f m) 
Monoid x => Plus (OpT f x) 
(Monoid w, Functor m, MonadPlus m) => Plus (RWST r w s m) 

newtype OpT f a b Source

Like Op but apply another type.

Constructors

OpT 

Fields

getOpT :: f b -> a
 

Instances

Comonad f => Category (OpT f) 
Functor f => Contravariant (OpT f x) 
Monoid x => Plus (OpT f x) 

Yoneda

newtype Yoneda f x Source

Right Yoneda lemma

Constructors

Yoneda 

Fields

runYoneda :: forall z. (x -> z) -> f z
 

Instances

Functor (Yoneda f) 
Plus f => Plus (Yoneda f) 

unreduceYoneda :: Functor w => (forall z. w z -> f z) -> w x -> Yoneda f xSource

Build the right Yoneda by specifying the translation from a functor to anything.

CoYoneda

data CoYoneda f x Source

Left Yoneda lemma

Constructors

forall z . CoYoneda (z -> x) (f z) 

Instances

reduceCoYoneda :: Functor m => (forall z. f z -> m z) -> CoYoneda f x -> m xSource

Lower the left Yoneda by specifying the translation from the inner type to any functor.

Free monad

data Free f x Source

Free monad from a functor

Constructors

Pure x 
Free (f (Free f x)) 

Instances

ComonadHoist Free 
Functor f => Monad (Free f) 
Functor f => Functor (Free f) 
(Functor f, Plus f) => MonadPlus (Free f) 
Functor f => Applicative (Free f) 
(Functor f, Plus f) => Alternative (Free f) 
Plus f => Plus (Free f) 
(Eq (f (Free f a)), Eq a) => Eq (Free f a) 
(Ord (f (Free f a)), Ord a) => Ord (Free f a) 
(Read (f (Free f a)), Read a) => Read (Free f a) 
(Show (f (Free f a)), Show a) => Show (Free f a) 

reduceFree :: Monad m => (forall z. f z -> m z) -> Free f x -> m xSource

Lowers the free monad to another monad by giving the translation from the functor to the monad.

affectFree :: Functor g => (forall z. (s, f z) -> g (s, z)) -> (s, Free f x) -> Free g (s, x)Source

Affect each level of the structure and pass a result of reading them to the leaf nodes.

newtype FreeT f m r Source

Transformer of free monad.

Constructors

FreeT 

Fields

runFreeT :: m (Either r (f (FreeT f m r)))
 

Instances

MonadTrans (FreeT f) 
(Functor f, Monad m) => Monad (FreeT f m) 
(Functor f, Functor m) => Functor (FreeT f m) 
(Functor f, MonadPlus m) => MonadPlus (FreeT f m) 
(Functor f, Applicative m, Monad m) => Applicative (FreeT f m) 
(Functor f, Monad m, Alternative m) => Alternative (FreeT f m) 
Plus m => Plus (FreeT f m) 

reduceFreeT :: Monad m => (forall z. f z -> m z) -> FreeT f m x -> m xSource

As reduceFree for transformers (you must reduce to the monad being transformed).

Free comonad

data Cofree f x Source

Free comonad from a functor

Constructors

x :< (f (Cofree f x)) 

Instances

ComonadHoist Cofree 
Functor f => Functor (Cofree f) 
Applicative f => Applicative (Cofree f) 
Functor f => Comonad (Cofree f) 
Functor f => Extend (Cofree f) 
(Eq (f (Cofree f a)), Eq a) => Eq (Cofree f a) 
(Ord (f (Cofree f a)), Ord a) => Ord (Cofree f a) 
(Read (f (Cofree f a)), Read a) => Read (Cofree f a) 
(Show (f (Cofree f a)), Show a) => Show (Cofree f a) 

unreduceCofree :: Comonad w => (forall z. w z -> f z) -> w x -> Cofree f xSource

Build the free comonad from a comonad by giving the translation from the comonad to a functor.

affectCofree :: Functor g => (forall z. (s, f z) -> g (s, z)) -> (s, Cofree f x) -> Cofree g (s, x)Source

Affect each level of the structure and pass a result of reading them to each node.

data CofreeT f w x Source

Constructors

CofreeT (w x) (f (CofreeT f w x)) 

Instances

ComonadTrans (CofreeT f) 
(Functor f, Functor w) => Functor (CofreeT f w) 
(Functor f, Comonad w) => Comonad (CofreeT f w) 
(Functor f, Extend w) => Extend (CofreeT f w) 

unreduceCofreeT :: Comonad w => (forall z. w z -> f z) -> w x -> CofreeT f w xSource

As unreduceCofree for transformers (you must unreduce from the comonad being transformed).

Codensity monad

newtype Codensity f x Source

Codensity monad from anything (it doesn't have to be a functor)

Constructors

Codensity 

Fields

runCodensity :: forall z. (x -> f z) -> f z
 

lowerCodensity :: Applicative f => Codensity f x -> f xSource

You can reduce the codensity monad of any applicative functor to that applicative functor.

Density comonad

data Density f x Source

Density comonad from anything (it doesn't have to be a functor)

Constructors

forall z . Density (f z -> x) (f z) 

liftDensity :: Comonad w => w a -> Density w aSource

You can make the density comonad from any copointed functor.

Monads from comonads

newtype CoT w m a Source

Make a monad transformer from any comonad as Edward Kmett described.

Constructors

CoT 

Fields

runCoT :: forall r. w (a -> m r) -> m r
 

Instances

Comonad w => MonadTrans (CoT w) 
Comonad w => Monad (CoT w m) 
Functor w => Functor (CoT w m) 
(Comonad w, Plus m) => MonadPlus (CoT w m) 
Comonad w => Applicative (CoT w m) 
(Comonad w, Plus m) => Alternative (CoT w m) 

type Co w = CoT w IdentitySource

runCo :: Functor w => Co w a -> w (a -> r) -> rSource

liftCoT0 :: Comonad w => (forall a. w a -> s) -> CoT w m sSource

lowerCoT0 :: (Functor w, Applicative m) => CoT w m s -> w a -> m sSource

lowerCo0 :: Functor w => Co w s -> w a -> sSource

liftCoT1 :: (forall a. w a -> a) -> CoT w m ()Source

lowerCoT1 :: (Functor w, Applicative m) => CoT w m z -> w a -> m aSource

lowerCo1 :: Functor w => Co w z -> w a -> aSource

Codensity ask monad

newtype CodensityAsk w x Source

Codensity monad taking a parameter holding something related to the output type. If this parameter is a comonad, you get a MonadPlus.

Constructors

CodensityAsk 

Fields

runCodensityAsk :: forall z. w z -> (x -> z) -> z
 

peekCodensityAsk :: w x -> CodensityAsk w x -> xSource

Access the result of some CodensityAsk by specifying an input which corresponds to the result.

newtype CodensityAskT w m x Source

Constructors

CodensityAskT 

Fields

runCodensityAskT :: forall z. w (m z) -> (x -> m z) -> m z
 

peekCodensityAskT :: Applicative m => w (m x) -> CodensityAskT w m x -> m xSource

Density ask comonad

data DensityAskT p f x Source

Constructors

forall z . DensityAskT (p z -> f z -> x) (f z) 

Instances

type DensityAsk p = DensityAskT p IdentitySource

Density comonad taking a parameter holding something related to the output type. If this parameter is a Plus, you get a comonad.

Miscellaneous

data Finalize x Source

Finalize monad on '(->)' category. (The Finalize monad is the only possible monad of a endofunctor taking all objects to one final object of the category.)

Constructors

Finalize 

data Initialize x Source

Initialize comonad on '(->)' category. (The Initialize comonad is dual to the Finalize monad.)

data Decompose whereSource

Constructors

Decompose :: y z -> Decompose x y (x z) 

Instances

data Recompose whereSource

Constructors

Recompose :: forall w x y z. w x y (x z) -> Recompose w y z 

Instances of types from other modules

newtype Op a b

Dual function arrows.

Constructors

Op 

Fields

getOp :: b -> a
 

Instances

newtype Endo a

The monoid of endomorphisms under composition.

Constructors

Endo 

Fields

appEndo :: a -> a
 

Instances

newtype Const a b

Constructors

Const 

Fields

getConst :: a
 

Instances

Functor (Const m) 
Monoid m => Applicative (Const m) 
Monoid x => Alternative (Const x) 
Contravariant (Const a)

Control.Applicative.Const

Monoid x => Plus (Const x)