free-algebras-0.1.0.1: Free algebras

Control.Algebra.Free

Synopsis

# Documentation

class FreeAlgebra1 (m :: (k -> Type) -> k -> Type) where Source #

Higher kinded version of FreeAlgebra. Instances includes free functors, free applicative functors, free monads, state monads etc.

A lawful instance should guarantee that foldNatFree is an isomorphism with inverses unFoldNatFree.

This guaranties that m is a left adjoint functor from the category of types of kind Type -> Type which satisfy AlgebraType0 m constraint, to the category of types of kind Type -> Type which satisfy the AlgebraType m constraint. This functor is left adjoin to the forgetful functor (which is well defined if the laws on AlgebraType0 family are satisfied. This in turn guarantees that m composed with this forgetful functor is a monad. In result we get monadic operations:

• return = liftFree
• (>>=)  = bindFree1
• join   = joinFree1

For m such that AlgebraType0 subsumes Monad this class implies:

• MFunctor via hoist = hoistFree1
• MMonad via embed = flip bindFree1
• MonadTrans via lift = liftFree

Minimal complete definition

Methods

liftFree :: AlgebraType0 m f => f a -> m f a Source #

Natural transformation that embeds generators into m.

Arguments

 :: forall d f a. (AlgebraType m d, AlgebraType0 m f) => (forall x. f x -> d x) a natural transformation which embeds generators of m into d -> m f a -> d a a morphism from m f to d

The freeness property.

foldNatFree nat (liftFree m) = nat m
foldNatFree nat . foldNatFree nat' = foldNatFree (foldNatFree nat . nat')

codom1 :: forall f. AlgebraType0 m f => Proof (AlgebraType m (m f)) (m f) Source #

A proof that AlgebraType m (m f) holds for all AlgebraType0 f => f. Together with hoistFree1 this proves that FreeAlgebra m => m is a functor from the full subcategory of types of kind Type -> Type which satisfy AlgebraType0 m f to ones that satisfy AlgebraType m f.

default codom1 :: forall a. AlgebraType m (m a) => Proof (AlgebraType m (m a)) (m a) Source #

forget1 :: forall f. AlgebraType m f => Proof (AlgebraType0 m f) (m f) Source #

A proof that the forgetful functor from the full subcategory of types of kind Type -> Type satisfying AlgebraType m f constraint to types satisfying AlgebraType0 m f is well defined.

default forget1 :: forall a. AlgebraType0 m a => Proof (AlgebraType0 m a) (m a) Source #

#### Instances

Instances details
 FreeAlgebra1 (ReaderT r :: (Type -> Type) -> Type -> Type) Source # ReaderT is a free monad in the class of all MonadReader monads. Instance detailsDefined in Control.Algebra.Free MethodsliftFree :: forall f (a :: k). AlgebraType0 (ReaderT r) f => f a -> ReaderT r f a Source #foldNatFree :: forall d f (a :: k). (AlgebraType (ReaderT r) d, AlgebraType0 (ReaderT r) f) => (forall (x :: k). f x -> d x) -> ReaderT r f a -> d a Source #codom1 :: forall (f :: k -> Type). AlgebraType0 (ReaderT r) f => Proof (AlgebraType (ReaderT r) (ReaderT r f)) (ReaderT r f) Source #forget1 :: forall (f :: k -> Type). AlgebraType (ReaderT r) f => Proof (AlgebraType0 (ReaderT r) f) (ReaderT r f) Source # (forall (f :: Type -> Type). c (Free1 c f)) => FreeAlgebra1 (Free1 c :: (Type -> Type) -> Type -> Type) Source # Instance detailsDefined in Control.Algebra.Free MethodsliftFree :: forall f (a :: k). AlgebraType0 (Free1 c) f => f a -> Free1 c f a Source #foldNatFree :: forall d f (a :: k). (AlgebraType (Free1 c) d, AlgebraType0 (Free1 c) f) => (forall (x :: k). f x -> d x) -> Free1 c f a -> d a Source #codom1 :: forall (f :: k -> Type). AlgebraType0 (Free1 c) f => Proof (AlgebraType (Free1 c) (Free1 c f)) (Free1 c f) Source #forget1 :: forall (f :: k -> Type). AlgebraType (Free1 c) f => Proof (AlgebraType0 (Free1 c) f) (Free1 c f) Source # Monad m => FreeAlgebra1 (FreeMAction m :: (Type -> Type) -> Type -> Type) Source # Instance detailsDefined in Control.Monad.Action MethodsliftFree :: forall f (a :: k). AlgebraType0 (FreeMAction m) f => f a -> FreeMAction m f a Source #foldNatFree :: forall d f (a :: k). (AlgebraType (FreeMAction m) d, AlgebraType0 (FreeMAction m) f) => (forall (x :: k). f x -> d x) -> FreeMAction m f a -> d a Source #codom1 :: forall (f :: k -> Type). AlgebraType0 (FreeMAction m) f => Proof (AlgebraType (FreeMAction m) (FreeMAction m f)) (FreeMAction m f) Source #forget1 :: forall (f :: k -> Type). AlgebraType (FreeMAction m) f => Proof (AlgebraType0 (FreeMAction m) f) (FreeMAction m f) Source # Source # Instance detailsDefined in Control.Algebra.Free MethodsliftFree :: forall f (a :: k). AlgebraType0 MaybeT f => f a -> MaybeT f a Source #foldNatFree :: forall d f (a :: k). (AlgebraType MaybeT d, AlgebraType0 MaybeT f) => (forall (x :: k). f x -> d x) -> MaybeT f a -> d a Source #codom1 :: forall (f :: k -> Type). AlgebraType0 MaybeT f => Proof (AlgebraType MaybeT (MaybeT f)) (MaybeT f) Source #forget1 :: forall (f :: k -> Type). AlgebraType MaybeT f => Proof (AlgebraType0 MaybeT f) (MaybeT f) Source # Source # Instance detailsDefined in Control.Algebra.Free MethodsliftFree :: forall f (a :: k). AlgebraType0 F f => f a -> F f a Source #foldNatFree :: forall d f (a :: k). (AlgebraType F d, AlgebraType0 F f) => (forall (x :: k). f x -> d x) -> F f a -> d a Source #codom1 :: forall (f :: k -> Type). AlgebraType0 F f => Proof (AlgebraType F (F f)) (F f) Source #forget1 :: forall (f :: k -> Type). AlgebraType F f => Proof (AlgebraType0 F f) (F f) Source # Source # Free monad is free in the class of monad over the class of functors. Instance detailsDefined in Control.Algebra.Free MethodsliftFree :: forall f (a :: k). AlgebraType0 Free f => f a -> Free f a Source #foldNatFree :: forall d f (a :: k). (AlgebraType Free d, AlgebraType0 Free f) => (forall (x :: k). f x -> d x) -> Free f a -> d a Source #codom1 :: forall (f :: k -> Type). AlgebraType0 Free f => Proof (AlgebraType Free (Free f)) (Free f) Source #forget1 :: forall (f :: k -> Type). AlgebraType Free f => Proof (AlgebraType0 Free f) (Free f) Source # Source # Instance detailsDefined in Control.Algebra.Free MethodsliftFree :: forall f (a :: k). AlgebraType0 Ap f => f a -> Ap f a Source #foldNatFree :: forall d f (a :: k). (AlgebraType Ap d, AlgebraType0 Ap f) => (forall (x :: k). f x -> d x) -> Ap f a -> d a Source #codom1 :: forall (f :: k -> Type). AlgebraType0 Ap f => Proof (AlgebraType Ap (Ap f)) (Ap f) Source #forget1 :: forall (f :: k -> Type). AlgebraType Ap f => Proof (AlgebraType0 Ap f) (Ap f) Source # Source # Instance detailsDefined in Control.Algebra.Free MethodsliftFree :: forall f (a :: k). AlgebraType0 Ap f => f a -> Ap f a Source #foldNatFree :: forall d f (a :: k). (AlgebraType Ap d, AlgebraType0 Ap f) => (forall (x :: k). f x -> d x) -> Ap f a -> d a Source #codom1 :: forall (f :: k -> Type). AlgebraType0 Ap f => Proof (AlgebraType Ap (Ap f)) (Ap f) Source #forget1 :: forall (f :: k -> Type). AlgebraType Ap f => Proof (AlgebraType0 Ap f) (Ap f) Source # Source # Ap is a free in the class of applicative functors, over any functor (Ap f is applicative whenever f is a functor) Instance detailsDefined in Control.Algebra.Free MethodsliftFree :: forall f (a :: k). AlgebraType0 Ap f => f a -> Ap f a Source #foldNatFree :: forall d f (a :: k). (AlgebraType Ap d, AlgebraType0 Ap f) => (forall (x :: k). f x -> d x) -> Ap f a -> d a Source #codom1 :: forall (f :: k -> Type). AlgebraType0 Ap f => Proof (AlgebraType Ap (Ap f)) (Ap f) Source #forget1 :: forall (f :: k -> Type). AlgebraType Ap f => Proof (AlgebraType0 Ap f) (Ap f) Source # Source # Instance detailsDefined in Control.Algebra.Free MethodsliftFree :: forall f (a :: k). AlgebraType0 Alt f => f a -> Alt f a Source #foldNatFree :: forall d f (a :: k). (AlgebraType Alt d, AlgebraType0 Alt f) => (forall (x :: k). f x -> d x) -> Alt f a -> d a Source #codom1 :: forall (f :: k -> Type). AlgebraType0 Alt f => Proof (AlgebraType Alt (Alt f)) (Alt f) Source #forget1 :: forall (f :: k -> Type). AlgebraType Alt f => Proof (AlgebraType0 Alt f) (Alt f) Source # Source # Instance detailsDefined in Control.Algebra.Free MethodsliftFree :: forall f (a :: k). AlgebraType0 Coyoneda f => f a -> Coyoneda f a Source #foldNatFree :: forall d f (a :: k). (AlgebraType Coyoneda d, AlgebraType0 Coyoneda f) => (forall (x :: k). f x -> d x) -> Coyoneda f a -> d a Source #codom1 :: forall (f :: k -> Type). AlgebraType0 Coyoneda f => Proof (AlgebraType Coyoneda (Coyoneda f)) (Coyoneda f) Source #forget1 :: forall (f :: k -> Type). AlgebraType Coyoneda f => Proof (AlgebraType0 Coyoneda f) (Coyoneda f) Source # Source # Instance detailsDefined in Control.Algebra.Free MethodsliftFree :: forall f (a :: k). AlgebraType0 ListT f => f a -> ListT f a Source #foldNatFree :: forall d f (a :: k). (AlgebraType ListT d, AlgebraType0 ListT f) => (forall (x :: k). f x -> d x) -> ListT f a -> d a Source #codom1 :: forall (f :: k -> Type). AlgebraType0 ListT f => Proof (AlgebraType ListT (ListT f)) (ListT f) Source #forget1 :: forall (f :: k -> Type). AlgebraType ListT f => Proof (AlgebraType0 ListT f) (ListT f) Source # Source # DayF, as Ap is a free applicative functor, but over applicative functors (DayF f is applicative if f is an applicative functor). Instance detailsDefined in Control.Algebra.Free MethodsliftFree :: forall f (a :: k). AlgebraType0 DayF f => f a -> DayF f a Source #foldNatFree :: forall d f (a :: k). (AlgebraType DayF d, AlgebraType0 DayF f) => (forall (x :: k). f x -> d x) -> DayF f a -> d a Source #codom1 :: forall (f :: k -> Type). AlgebraType0 DayF f => Proof (AlgebraType DayF (DayF f)) (DayF f) Source #forget1 :: forall (f :: k -> Type). AlgebraType DayF f => Proof (AlgebraType0 DayF f) (DayF f) Source # FreeAlgebra1 (ExceptT e :: (Type -> Type) -> Type -> Type) Source # ExceptT e is a free algebra among all MonadError e monads. Instance detailsDefined in Control.Algebra.Free MethodsliftFree :: forall f (a :: k). AlgebraType0 (ExceptT e) f => f a -> ExceptT e f a Source #foldNatFree :: forall d f (a :: k). (AlgebraType (ExceptT e) d, AlgebraType0 (ExceptT e) f) => (forall (x :: k). f x -> d x) -> ExceptT e f a -> d a Source #codom1 :: forall (f :: k -> Type). AlgebraType0 (ExceptT e) f => Proof (AlgebraType (ExceptT e) (ExceptT e f)) (ExceptT e f) Source #forget1 :: forall (f :: k -> Type). AlgebraType (ExceptT e) f => Proof (AlgebraType0 (ExceptT e) f) (ExceptT e f) Source # FreeAlgebra1 (StateT s :: (Type -> Type) -> Type -> Type) Source # Lazy StateT monad transformer is a free algebra in the class of monads which satisfy the MonadState constraint. Note that this instance captures that StateT s is a monad transformer: liftFree = lift This is also true for all the other monad transformers. Instance detailsDefined in Control.Algebra.Free MethodsliftFree :: forall f (a :: k). AlgebraType0 (StateT s) f => f a -> StateT s f a Source #foldNatFree :: forall d f (a :: k). (AlgebraType (StateT s) d, AlgebraType0 (StateT s) f) => (forall (x :: k). f x -> d x) -> StateT s f a -> d a Source #codom1 :: forall (f :: k -> Type). AlgebraType0 (StateT s) f => Proof (AlgebraType (StateT s) (StateT s f)) (StateT s f) Source #forget1 :: forall (f :: k -> Type). AlgebraType (StateT s) f => Proof (AlgebraType0 (StateT s) f) (StateT s f) Source # FreeAlgebra1 (StateT s :: (Type -> Type) -> Type -> Type) Source # Strict StateT monad transformer is also a free algebra, thus hoistFreeH is an isomorphism between the strict and lazy versions. Instance detailsDefined in Control.Algebra.Free MethodsliftFree :: forall f (a :: k). AlgebraType0 (StateT s) f => f a -> StateT s f a Source #foldNatFree :: forall d f (a :: k). (AlgebraType (StateT s) d, AlgebraType0 (StateT s) f) => (forall (x :: k). f x -> d x) -> StateT s f a -> d a Source #codom1 :: forall (f :: k -> Type). AlgebraType0 (StateT s) f => Proof (AlgebraType (StateT s) (StateT s f)) (StateT s f) Source #forget1 :: forall (f :: k -> Type). AlgebraType (StateT s) f => Proof (AlgebraType0 (StateT s) f) (StateT s f) Source # FreeAlgebra1 (WriterT w :: (Type -> Type) -> Type -> Type) Source # Lazy WriterT is free for algebras of type MonadWriter. Instance detailsDefined in Control.Algebra.Free MethodsliftFree :: forall f (a :: k). AlgebraType0 (WriterT w) f => f a -> WriterT w f a Source #foldNatFree :: forall d f (a :: k). (AlgebraType (WriterT w) d, AlgebraType0 (WriterT w) f) => (forall (x :: k). f x -> d x) -> WriterT w f a -> d a Source #codom1 :: forall (f :: k -> Type). AlgebraType0 (WriterT w) f => Proof (AlgebraType (WriterT w) (WriterT w f)) (WriterT w f) Source #forget1 :: forall (f :: k -> Type). AlgebraType (WriterT w) f => Proof (AlgebraType0 (WriterT w) f) (WriterT w f) Source # FreeAlgebra1 (WriterT w :: (Type -> Type) -> Type -> Type) Source # Strict WriterT monad transformer is a free algebra among all MonadWriters. Instance detailsDefined in Control.Algebra.Free MethodsliftFree :: forall f (a :: k). AlgebraType0 (WriterT w) f => f a -> WriterT w f a Source #foldNatFree :: forall d f (a :: k). (AlgebraType (WriterT w) d, AlgebraType0 (WriterT w) f) => (forall (x :: k). f x -> d x) -> WriterT w f a -> d a Source #codom1 :: forall (f :: k -> Type). AlgebraType0 (WriterT w) f => Proof (AlgebraType (WriterT w) (WriterT w f)) (WriterT w f) Source #forget1 :: forall (f :: k -> Type). AlgebraType (WriterT w) f => Proof (AlgebraType0 (WriterT w) f) (WriterT w f) Source # FreeAlgebra1 (RWST r w s :: (Type -> Type) -> Type -> Type) Source # Instance detailsDefined in Control.Algebra.Free MethodsliftFree :: forall f (a :: k). AlgebraType0 (RWST r w s) f => f a -> RWST r w s f a Source #foldNatFree :: forall d f (a :: k). (AlgebraType (RWST r w s) d, AlgebraType0 (RWST r w s) f) => (forall (x :: k). f x -> d x) -> RWST r w s f a -> d a Source #codom1 :: forall (f :: k -> Type). AlgebraType0 (RWST r w s) f => Proof (AlgebraType (RWST r w s) (RWST r w s f)) (RWST r w s f) Source #forget1 :: forall (f :: k -> Type). AlgebraType (RWST r w s) f => Proof (AlgebraType0 (RWST r w s) f) (RWST r w s f) Source # FreeAlgebra1 (RWST r w s :: (Type -> Type) -> Type -> Type) Source # Instance detailsDefined in Control.Algebra.Free MethodsliftFree :: forall f (a :: k). AlgebraType0 (RWST r w s) f => f a -> RWST r w s f a Source #foldNatFree :: forall d f (a :: k). (AlgebraType (RWST r w s) d, AlgebraType0 (RWST r w s) f) => (forall (x :: k). f x -> d x) -> RWST r w s f a -> d a Source #codom1 :: forall (f :: k -> Type). AlgebraType0 (RWST r w s) f => Proof (AlgebraType (RWST r w s) (RWST r w s f)) (RWST r w s f) Source #forget1 :: forall (f :: k -> Type). AlgebraType (RWST r w s) f => Proof (AlgebraType0 (RWST r w s) f) (RWST r w s f) Source #

## Type level witnesses

data Proof (c :: Constraint) (a :: l) where Source #

A proof that constraint c holds for type a.

Constructors

 Proof :: c => Proof c a

## Higher algebra type / constraints

type family AlgebraType0 (f :: k) (a :: l) :: Constraint Source #

Type family which limits Hask to its full subcategory which satisfies a given constraints. Some free algebras, like free groups, or free abelian semigroups have additional constraints on on generators, like Eq or Ord.

#### Instances

Instances details
 type AlgebraType0 Coyoneda (g :: l) Source # Algebras of the same type as Coyoneda are all functors. Instance detailsDefined in Control.Algebra.Free type AlgebraType0 Coyoneda (g :: l) = () type AlgebraType0 DList (a :: l) Source # Instance detailsDefined in Data.Algebra.Free type AlgebraType0 DList (a :: l) = () type AlgebraType0 Maybe (a :: l) Source # Instance detailsDefined in Data.Algebra.Free type AlgebraType0 Maybe (a :: l) = () type AlgebraType0 [] (a :: l) Source # Instance detailsDefined in Data.Algebra.Free type AlgebraType0 [] (a :: l) = () type AlgebraType0 NonEmpty (a :: l) Source # Instance detailsDefined in Data.Algebra.Free type AlgebraType0 NonEmpty (a :: l) = () type AlgebraType0 Identity (a :: l) Source # Instance detailsDefined in Data.Algebra.Free type AlgebraType0 Identity (a :: l) = () type AlgebraType0 DNonEmpty (a :: l) Source # Instance detailsDefined in Data.Algebra.Free type AlgebraType0 DNonEmpty (a :: l) = () type AlgebraType0 (Free1 c :: (Type -> Type) -> Type -> Type) (f :: l) Source # Instance detailsDefined in Control.Algebra.Free type AlgebraType0 (Free1 c :: (Type -> Type) -> Type -> Type) (f :: l) = () type AlgebraType0 (Free Group) (a :: l) Source # Instance detailsDefined in Data.Algebra.Free type AlgebraType0 (Free Group) (a :: l) = () type AlgebraType0 (Free Monoid) (a :: l) Source # Instance detailsDefined in Data.Algebra.Free type AlgebraType0 (Free Monoid) (a :: l) = () type AlgebraType0 (Free Semigroup) (a :: l) Source # Instance detailsDefined in Data.Algebra.Free type AlgebraType0 (Free Semigroup) (a :: l) = () type AlgebraType0 FreeGroupL (a :: Type) Source # Instance detailsDefined in Data.Group.Free type AlgebraType0 FreeGroupL (a :: Type) = Eq a type AlgebraType0 FreeGroup (a :: Type) Source # Instance detailsDefined in Data.Group.Free type AlgebraType0 FreeGroup (a :: Type) = Eq a type AlgebraType0 FreeAbelianSemigroup (a :: Type) Source # Instance detailsDefined in Data.Semigroup.Abelian type AlgebraType0 FreeAbelianSemigroup (a :: Type) = Ord a type AlgebraType0 FreeAbelianMonoid (a :: Type) Source # Instance detailsDefined in Data.Monoid.Abelian type AlgebraType0 FreeAbelianMonoid (a :: Type) = Ord a type AlgebraType0 FreeSemilattice (a :: Type) Source # Instance detailsDefined in Data.Semigroup.Semilattice type AlgebraType0 FreeSemilattice (a :: Type) = Ord a type AlgebraType0 MaybeT (m :: Type -> Type) Source # Instance detailsDefined in Control.Algebra.Free type AlgebraType0 MaybeT (m :: Type -> Type) = Monad m type AlgebraType0 F (f :: Type -> Type) Source # Instance detailsDefined in Control.Algebra.Free type AlgebraType0 F (f :: Type -> Type) = Functor f type AlgebraType0 Free (f :: Type -> Type) Source # Algebras of the same type as Free monad is the class of all monads. Instance detailsDefined in Control.Algebra.Free type AlgebraType0 Free (f :: Type -> Type) = Functor f type AlgebraType0 Ap (g :: Type -> Type) Source # Instance detailsDefined in Control.Algebra.Free type AlgebraType0 Ap (g :: Type -> Type) = Functor g type AlgebraType0 Ap (g :: Type -> Type) Source # Instance detailsDefined in Control.Algebra.Free type AlgebraType0 Ap (g :: Type -> Type) = Functor g type AlgebraType0 Ap (g :: Type -> Type) Source # Algebras of the same type as Ap are the applicative functors. Instance detailsDefined in Control.Algebra.Free type AlgebraType0 Ap (g :: Type -> Type) = Functor g type AlgebraType0 Alt (f :: Type -> Type) Source # Instance detailsDefined in Control.Algebra.Free type AlgebraType0 Alt (f :: Type -> Type) = Functor f type AlgebraType0 ListT (f :: Type -> Type) Source # Instance detailsDefined in Control.Algebra.Free type AlgebraType0 ListT (f :: Type -> Type) = Monad f type AlgebraType0 DayF (g :: Type -> Type) Source # Algebras of the same type as DayF are all the applicative functors. Instance detailsDefined in Control.Algebra.Free type AlgebraType0 DayF (g :: Type -> Type) = Applicative g type AlgebraType0 (FreeMAction m :: (Type -> Type) -> Type -> Type) (f :: Type -> Type) Source # Instance detailsDefined in Control.Monad.Action type AlgebraType0 (FreeMAction m :: (Type -> Type) -> Type -> Type) (f :: Type -> Type) = Functor f type AlgebraType0 (ExceptT e :: (Type -> Type) -> Type -> Type) (m :: Type -> Type) Source # Algebras of the same type as ReaderT monad is the class of all reader monads. Instance detailsDefined in Control.Algebra.Free type AlgebraType0 (ExceptT e :: (Type -> Type) -> Type -> Type) (m :: Type -> Type) = Monad m type AlgebraType0 (ReaderT r :: (Type -> Type) -> Type -> Type) (m :: Type -> Type) Source # Algebras of the same type as ReaderT monad is the class of all reader monads.TODO: take advantage of poly-kinded ReaderT Instance detailsDefined in Control.Algebra.Free type AlgebraType0 (ReaderT r :: (Type -> Type) -> Type -> Type) (m :: Type -> Type) = Monad m type AlgebraType0 (StateT s :: (Type -> Type) -> Type -> Type) (m :: Type -> Type) Source # Algebras of the same type as StateT monad is the class of all state monads. Instance detailsDefined in Control.Algebra.Free type AlgebraType0 (StateT s :: (Type -> Type) -> Type -> Type) (m :: Type -> Type) = Monad m type AlgebraType0 (StateT s :: (Type -> Type) -> Type -> Type) (m :: Type -> Type) Source # Algebras of the same type as StateT monad is the class of all state monads. Instance detailsDefined in Control.Algebra.Free type AlgebraType0 (StateT s :: (Type -> Type) -> Type -> Type) (m :: Type -> Type) = Monad m type AlgebraType0 (WriterT w :: (Type -> Type) -> Type -> Type) (m :: Type -> Type) Source # Algebras of the same type as WriterT monad is the class of all writer monads. Instance detailsDefined in Control.Algebra.Free type AlgebraType0 (WriterT w :: (Type -> Type) -> Type -> Type) (m :: Type -> Type) = (Monad m, Monoid w) type AlgebraType0 (WriterT w :: (Type -> Type) -> Type -> Type) (m :: Type -> Type) Source # Algebras of the same type as WriterT monad is the class of all writer monads. Instance detailsDefined in Control.Algebra.Free type AlgebraType0 (WriterT w :: (Type -> Type) -> Type -> Type) (m :: Type -> Type) = (Monad m, Monoid w) type AlgebraType0 (RWST r w s :: (Type -> Type) -> Type -> Type) (m :: Type -> Type) Source # Instance detailsDefined in Control.Algebra.Free type AlgebraType0 (RWST r w s :: (Type -> Type) -> Type -> Type) (m :: Type -> Type) = (Monad m, Monoid w) type AlgebraType0 (RWST r w s :: (Type -> Type) -> Type -> Type) (m :: Type -> Type) Source # Instance detailsDefined in Control.Algebra.Free type AlgebraType0 (RWST r w s :: (Type -> Type) -> Type -> Type) (m :: Type -> Type) = (Monad m, Monoid w)

type family AlgebraType (f :: k) (a :: l) :: Constraint Source #

Type family which for each free algebra m returns a type level lambda from types to constraints. It is describe the class of algebras for which this free algebra is free.

A lawful instance for this type family must guarantee that the constraint AlgebraType0 m f is implied by the AlgebraType m f constraint. This guarantees that there exists a forgetful functor from the category of types of kind * -> * which satisfy AlgebraType m constrain to the category of types of kind * -> * which satisfy the 'AlgebraType0 m constraint.

#### Instances

Instances details

# Combinators

wrapFree :: forall (m :: (Type -> Type) -> Type -> Type) (f :: Type -> Type) a. (FreeAlgebra1 m, AlgebraType0 m f, Monad (m f)) => f (m f a) -> m f a Source #

Anything that carries FreeAlgebra1 constraint is also an instance of MonadFree, but not vice versa. You can use wrap to define a MonadFree instance. ContT is an example of a monad which does have an FreeAlgebra1 instance, but has an MonadFree instance.

The Monad constrain will be satisfied for many monads through the 'AlgebraType m' constraint.

foldFree1 :: forall m f a. (FreeAlgebra1 m, AlgebraType m f) => m f a -> f a Source #

FreeAlgebra1 m implies that m f is a foldable.

 foldFree1 . liftFree == id :: f a -> f a


foldFree1 is the unit of the adjunction imposed by FreeAlgebra1 constraint.

It can be specialized to:

• lowerCoyoneda :: Functor f => Coyoneda f a -> f a
• retractAp :: Applicative f => Ap f a -> f a
• retract :: Monad f => Free f a -> f a

unFoldNatFree :: (FreeAlgebra1 m, AlgebraType0 m f) => (forall x. m f x -> d x) -> f a -> d a Source #

unFoldNatFree is an inverse of foldNatFree

It is uniquelly determined by its universal property (by Yonneda lemma):

unFoldNatFree id = ruturnFree1

Note that unFoldNatFree id is the unit of the adjunction imposed by the FreeAlgebra1 constraint.

Arguments

 :: forall m f g a. (FreeAlgebra1 m, AlgebraType0 m g, AlgebraType0 m f) => (forall x. f x -> g x) a natural transformation f ~> g -> m f a -> m g a

This is a functor instance for m when considered as an endofuctor of some subcategory of Type -> Type (e.g. endofunctors of Hask) and it satisfies the functor laws:

hoistFree1 id = id
hoistFree1 f . hoistFree1 g = hoistFree1 (f . g)

It can be specialized to:

• hoistAp :: (forall a. f a -> g a) -> Ap f b -> Ap g b
• hoistFree :: Functor g => (forall a. f a -> g a) -> Free f b -> Free g b
• Control.Monad.Morph.hoist for FreeAlgebra1 m => m such that AlgebraType0 m subsumes Monad m, e.g. StateT, WriterT or ReaderT.

hoistFreeH :: forall m n f a. (FreeAlgebra1 m, FreeAlgebra1 n, AlgebraType0 m f, AlgebraType0 n f, AlgebraType m (n f)) => m f a -> n f a Source #

 hoistFreeH . hoistFreeH = hoistFreeH


and when FreeAlgebra1 m ~ FreeAlgebra1 n:

 hoistFreeH = id


joinFree1 :: forall m f a. (FreeAlgebra1 m, AlgebraType0 m f) => m (m f) a -> m f a Source #

joinFree1 makes m a monad in some subcatgory of types of kind Type -> Type (usually the endo-functor category of Hask). It is just a specialization of foldFree1.

Arguments

 :: forall m f g a. (FreeAlgebra1 m, AlgebraType0 m g, AlgebraType0 m f) => m f a -> (forall x. f x -> m g x) natural transformation f ~> m g -> m g a

Bind operator for the joinFree1 monad, this is just foldNatFree in disguise.

For StateT, WriterT or ReaderT (or any FreeAlgebra1 m => m such that AlgebraType0 m subsumes Monad m), this is the >>= version of Control.Monad.Morph.embed.

assocFree1 :: forall m f a. (FreeAlgebra1 m, AlgebraType m f, Functor (m (m f))) => m f (m f a) -> m (m f) (f a) Source #

iterFree1 :: forall m f a. (FreeAlgebra1 m, AlgebraType0 m f, AlgebraType m Identity) => (forall x. f x -> x) -> m f a -> a Source #

Specialization of foldNatFree @_ @Identity; it will further specialize to:

• \_ -> runIdentity . lowerCoyoneda
• iterAp :: Functor g => (g a -> a) -> Ap g a -> a
• iter :: Functor f => (f a -> a) -> Free f a -> a

cataFree1 :: forall m f a. (FreeAlgebra1 m, AlgebraType m f, Monad f, Traversable (m f)) => Fix (m f) -> f a Source #

Fix (m f) is the initial algebra of type AlgebraType m and AlgebraType0 f.

# Day convolution

newtype DayF f a Source #

Day f f newtype wrapper. It is isomorphic with Ap f for applicative functors f via dayToAp (and apToDay).

Constructors

 DayF FieldsrunDayF :: Day f f a

#### Instances

Instances details

# Various classes (higher algebra types)

Algebra type for ListT monad transformer.

Methods

mempty1 :: m a Source #

mappend1 :: m a -> m a -> m a Source #

#### Instances

Instances details
 Monad m => MonadList (ListT m) Source # Instance detailsDefined in Control.Algebra.Free Methodsmempty1 :: ListT m a Source #mappend1 :: ListT m a -> ListT m a -> ListT m a Source #

class MonadMaybe m where Source #

A higher version Pointed class.

With QuantifiedConstraints this class will be redundant.

Methods

point :: forall a. m a Source #

#### Instances

Instances details
 Monad m => MonadMaybe (MaybeT m :: Type -> Type) Source # Instance detailsDefined in Control.Algebra.Free Methodspoint :: forall (a :: k). MaybeT m a Source #