| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Control.Algebra.Free
Contents
Synopsis
- class FreeAlgebra1 (m :: (k -> Type) -> k -> Type) where
- liftFree :: AlgebraType0 m f => f a -> m f a
- foldNatFree :: forall d f a. (AlgebraType m d, AlgebraType0 m f) => (forall x. f x -> d x) -> m f a -> d a
- codom1 :: forall f. AlgebraType0 m f => Proof (AlgebraType m (m f)) (m f)
- forget1 :: forall f. AlgebraType m f => Proof (AlgebraType0 m f) (m f)
- data Proof (c :: Constraint) (a :: l) where
- type family AlgebraType0 (f :: k) (a :: l) :: Constraint
- type family AlgebraType (f :: k) (a :: l) :: Constraint
- 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
- foldFree1 :: forall m f a. (FreeAlgebra1 m, AlgebraType m f) => m f a -> f a
- unFoldNatFree :: (FreeAlgebra1 m, AlgebraType0 m f) => (forall x. m f x -> d x) -> f a -> d a
- hoistFree1 :: forall m f g a. (FreeAlgebra1 m, AlgebraType0 m g, AlgebraType0 m f) => (forall x. f x -> g x) -> m f a -> m g a
- 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
- joinFree1 :: forall m f a. (FreeAlgebra1 m, AlgebraType0 m f) => m (m f) a -> m f a
- bindFree1 :: forall m f g a. (FreeAlgebra1 m, AlgebraType0 m g, AlgebraType0 m f) => m f a -> (forall x. f x -> m g x) -> m g a
- assocFree1 :: forall m f a. (FreeAlgebra1 m, AlgebraType m f, Functor (m (m f))) => m f (m f a) -> m (m f) (f a)
- iterFree1 :: forall m f a. (FreeAlgebra1 m, AlgebraType0 m f, AlgebraType m Identity) => (forall x. f x -> x) -> m f a -> a
- cataFree1 :: forall m f a. (FreeAlgebra1 m, AlgebraType m f, Monad f, Traversable (m f)) => Fix (m f) -> f a
- newtype DayF f a = DayF {}
- dayToAp :: Applicative f => Day f f a -> Ap f a
- apToDay :: Applicative f => Ap f a -> Day f f a
- newtype Free1 (c :: (Type -> Type) -> Constraint) (f :: Type -> Type) a = Free1 {
- runFree1 :: forall g. c g => (forall x. f x -> g x) -> g a
- class Monad m => MonadList m where
- class MonadMaybe m where
- point :: forall a. m a
Documentation
class FreeAlgebra1 (m :: (k -> Type) -> k -> Type) where Source #
Higher kinded version of . Instances includes free functors,
free applicative functors, free monads, state monads etc.FreeAlgebra
A lawful instance should guarantee that is an isomorphism
with inverses foldNatFree.unFoldNatFree
This guaranties that m is a left adjoint functor from the category of
types of kind Type -> Type which satisfy constraint, to the
category of types of kind AlgebraType0 mType -> Type which satisfy the
constraint. This functor is left adjoin to the forgetful functor (which is
well defined if the laws on AlgebraType m family are satisfied. This in
turn guarantees that AlgebraType0m composed with this forgetful functor is a monad.
In result we get monadic operations:
For m such that subsumes AlgebraType0 this class implies:Monad
MFunctorviahoist = hoistFree1MMonadviaembed = flip bindFree1MonadTransvialift = liftFree
Minimal complete definition
Methods
liftFree :: AlgebraType0 m f => f a -> m f a Source #
Natural transformation that embeds generators into m.
Arguments
| :: (AlgebraType m d, AlgebraType0 m f) | |
| => (forall x. f x -> d x) | a natural transformation which embeds generators of |
| -> m f a -> d a | a morphism from |
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 holds for all AlgebraType m (m f)AlgebraType0 f => f.
Together with this proves that hoistFree1FreeAlgebra m => m is
a functor from the full subcategory of types of kind Type -> Type
which satisfy to ones that satisfy AlgebraType0 m f.AlgebraType
m f
codom1 :: forall a. AlgebraType m (m a) => Proof (AlgebraType m (m a)) (m a) Source #
A proof that holds for all AlgebraType m (m f)AlgebraType0 f => f.
Together with this proves that hoistFree1FreeAlgebra m => m is
a functor from the full subcategory of types of kind Type -> Type
which satisfy to ones that satisfy AlgebraType0 m f.AlgebraType
m f
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 constraint to types
satisfying AlgebraType m f is well defined.AlgebraType0 m f
forget1 :: forall a. AlgebraType0 m a => Proof (AlgebraType0 m a) (m a) Source #
A proof that the forgetful functor from the full subcategory of types of
kind Type -> Type satisfying constraint to types
satisfying AlgebraType m f is well defined.AlgebraType0 m f
Instances
Type level witnesses
data Proof (c :: Constraint) (a :: l) where Source #
A proof that constraint c holds for type 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
| type AlgebraType0 Coyoneda (g :: l) Source # | Algebras of the same type as |
Defined in Control.Algebra.Free | |
| type AlgebraType0 DList (a :: l) Source # | |
Defined in Data.Algebra.Free | |
| type AlgebraType0 Maybe (a :: l) Source # | |
Defined in Data.Algebra.Free | |
| type AlgebraType0 [] (a :: l) Source # | |
Defined in Data.Algebra.Free type AlgebraType0 [] (a :: l) = () | |
| type AlgebraType0 NonEmpty (a :: l) Source # | |
Defined in Data.Algebra.Free | |
| type AlgebraType0 Identity (a :: l) Source # | |
Defined in Data.Algebra.Free | |
| type AlgebraType0 DNonEmpty (a :: l) Source # | |
Defined in Data.Algebra.Free | |
| type AlgebraType0 (Free1 c :: (Type -> Type) -> Type -> Type) (f :: l) Source # | |
Defined in Control.Algebra.Free | |
| type AlgebraType0 (Free Group) (a :: l) Source # | |
Defined in Data.Algebra.Free | |
| type AlgebraType0 (Free Monoid) (a :: l) Source # | |
Defined in Data.Algebra.Free | |
| type AlgebraType0 (Free Semigroup) (a :: l) Source # | |
Defined in Data.Algebra.Free | |
| type AlgebraType0 FreeGroupL (a :: Type) Source # | |
Defined in Data.Group.Free | |
| type AlgebraType0 FreeGroup (a :: Type) Source # | |
Defined in Data.Group.Free | |
| type AlgebraType0 FreeAbelianSemigroup (a :: Type) Source # | |
Defined in Data.Semigroup.Abelian | |
| type AlgebraType0 FreeAbelianMonoid (a :: Type) Source # | |
Defined in Data.Monoid.Abelian | |
| type AlgebraType0 FreeSemilattice (a :: Type) Source # | |
Defined in Data.Semigroup.Semilattice | |
| type AlgebraType0 MaybeT (m :: Type -> Type) Source # | |
Defined in Control.Algebra.Free | |
| type AlgebraType0 F (f :: Type -> Type) Source # | |
Defined in Control.Algebra.Free | |
| type AlgebraType0 Free (f :: Type -> Type) Source # | Algebras of the same type as |
Defined in Control.Algebra.Free | |
| type AlgebraType0 Ap (g :: Type -> Type) Source # | |
Defined in Control.Algebra.Free | |
| type AlgebraType0 Ap (g :: Type -> Type) Source # | |
Defined in Control.Algebra.Free | |
| type AlgebraType0 Ap (g :: Type -> Type) Source # | Algebras of the same type as |
Defined in Control.Algebra.Free | |
| type AlgebraType0 Alt (f :: Type -> Type) Source # | |
Defined in Control.Algebra.Free | |
| type AlgebraType0 ListT (f :: Type -> Type) Source # | |
Defined in Control.Algebra.Free | |
| type AlgebraType0 DayF (g :: Type -> Type) Source # | Algebras of the same type as |
Defined in Control.Algebra.Free | |
| type AlgebraType0 (FreeMAction m :: (Type -> Type) -> Type -> Type) (f :: Type -> Type) Source # | |
Defined in Control.Monad.Action | |
| type AlgebraType0 (ExceptT e :: (Type -> Type) -> Type -> Type) (m :: Type -> Type) Source # | Algebras of the same type as |
Defined in Control.Algebra.Free | |
| type AlgebraType0 (StateT s :: (Type -> Type) -> Type -> Type) (m :: Type -> Type) Source # | Algebras of the same type as |
Defined in Control.Algebra.Free | |
| type AlgebraType0 (StateT s :: (Type -> Type) -> Type -> Type) (m :: Type -> Type) Source # | Algebras of the same type as |
Defined in Control.Algebra.Free | |
| type AlgebraType0 (WriterT w :: (Type -> Type) -> Type -> Type) (m :: Type -> Type) Source # | Algebras of the same type as |
| type AlgebraType0 (WriterT w :: (Type -> Type) -> Type -> Type) (m :: Type -> Type) Source # | Algebras of the same type as |
| type AlgebraType0 (ReaderT r :: (k -> Type) -> k -> Type) (m :: Type -> Type) Source # | Algebras of the same type as TODO: take advantage of poly-kinded |
Defined in Control.Algebra.Free | |
| type AlgebraType0 (RWST r w s :: (Type -> Type) -> Type -> Type) (m :: Type -> Type) Source # | |
| type AlgebraType0 (RWST r w s :: (Type -> Type) -> Type -> Type) (m :: Type -> Type) Source # | |
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 is implied by the AlgebraType0 m f constraint. This guarantees that there exists a forgetful functor from
the category of types of kind AlgebraType
m f* -> * which satisfy
constrain to the category of types of kind AlgebraType m* -> * which satisfy the
'AlgebraType0 m constraint.
Instances
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 constraint is also an instance of
FreeAlgebra1, but not vice versa. You can use
MonadFree to define a wrap instance.
MonadFree is an example of a monad which does have an ContT
instance, but has an FreeAlgebra1 instance.MonadFree
The constrain will be satisfied for many monads through the
Monad'AlgebraType m' constraint.
foldFree1 :: forall m f a. (FreeAlgebra1 m, AlgebraType m f) => m f a -> f a Source #
implies that FreeAlgebra1 mm 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::Functorf =>Coyonedaf a -> f aretractAp::Applicativef =>Apf a -> f aretract::Monadf =>Freef a -> f a
unFoldNatFree :: (FreeAlgebra1 m, AlgebraType0 m f) => (forall x. m f x -> d x) -> f a -> d a Source #
is an inverse of unFoldNatFreefoldNatFree
It is uniquelly determined by its universal property (by Yonneda lemma):
unFoldNatFree id = ruturnFree1
Note that is the
unit of the
adjunction imposed by the unFoldNatFree id constraint.FreeAlgebra1
Arguments
| :: (FreeAlgebra1 m, AlgebraType0 m g, AlgebraType0 m f) | |
| => (forall x. f x -> g x) | a natural transformation |
| -> 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:
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 #
joinFree1 :: forall m f a. (FreeAlgebra1 m, AlgebraType0 m f) => m (m f) a -> m f a Source #
Arguments
| :: (FreeAlgebra1 m, AlgebraType0 m g, AlgebraType0 m f) | |
| => m f a | |
| -> (forall x. f x -> m g x) | natural transformation |
| -> m g a |
Bind operator for the monad, this is just joinFree1 in
disguise.foldNatFree
For ,
StateT or
WriterT (or any ReaderT such
that FreeAlgebra1 m => m subsumes AlgebraType0 m), this is the Monad m>>= 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 ; it will further specialize to:foldNatFree @_ @Identity
\_ ->
runIdentity.lowerCoyonedaiterAp::Functorg => (g a -> a) ->Apg a -> aiter::Functorf => (f a -> a) ->Freef a -> a
cataFree1 :: forall m f a. (FreeAlgebra1 m, AlgebraType m f, Monad f, Traversable (m f)) => Fix (m f) -> f a Source #
is the initial algebra of type Fix (m f) and
AlgebraType m.AlgebraType0 f
Day convolution
newtype wrapper. It is isomorphic with Day f f for
applicative functors Ap ff via (and dayToAp).apToDay
Instances
| Functor (DayF f) Source # | |
| Applicative f => Applicative (DayF f) Source # | |
| FreeAlgebra1 DayF Source # |
|
Defined in Control.Algebra.Free Methods liftFree :: AlgebraType0 DayF f => f a -> DayF f a Source # foldNatFree :: (AlgebraType DayF d, AlgebraType0 DayF f) => (forall (x :: k). f x -> d x) -> DayF f a -> d a Source # codom1 :: AlgebraType0 DayF f => Proof (AlgebraType DayF (DayF f)) (DayF f) Source # forget1 :: AlgebraType DayF f => Proof (AlgebraType0 DayF f) (DayF f) Source # | |
| type AlgebraType0 DayF (g :: Type -> Type) Source # | Algebras of the same type as |
Defined in Control.Algebra.Free | |
| type AlgebraType DayF (g :: Type -> Type) Source # | |
Defined in Control.Algebra.Free | |
Free construction in continuation passing style
newtype Free1 (c :: (Type -> Type) -> Constraint) (f :: Type -> Type) a Source #
Free construction for kinds . Type -> Type is
isomorhpic to Free1 Functor via Coyoneda, and hoistFreeH
is isomorphic to Free1 Applicative (also via Ap).hoistFreeH
Note: useful instance are only provided for ghc-8.6 using quantified constraints.
Instances
| (forall (f :: Type -> Type). c (Free1 c f)) => FreeAlgebra1 (Free1 c :: (Type -> Type) -> Type -> Type) Source # | |
Defined in Control.Algebra.Free Methods liftFree :: AlgebraType0 (Free1 c) f => f a -> Free1 c f a Source # foldNatFree :: (AlgebraType (Free1 c) d, AlgebraType0 (Free1 c) f) => (forall (x :: k). f x -> d x) -> Free1 c f a -> d a Source # codom1 :: AlgebraType0 (Free1 c) f => Proof (AlgebraType (Free1 c) (Free1 c f)) (Free1 c f) Source # forget1 :: AlgebraType (Free1 c) f => Proof (AlgebraType0 (Free1 c) f) (Free1 c f) Source # | |
| (forall (h :: Type -> Type). c h => Monad h) => Monad (Free1 c f) Source # | |
| (forall (h :: Type -> Type). c h => Functor h) => Functor (Free1 c f) Source # | |
| (forall (h :: Type -> Type). c h => Applicative h) => Applicative (Free1 c f) Source # |
|
| (forall (h :: Type -> Type). c h => MonadZip h) => MonadZip (Free1 c f) Source # | |
| (forall (h :: Type -> Type). c h => Alternative h) => Alternative (Free1 c f) Source # | |
| (forall (h :: Type -> Type). c h => MonadPlus h) => MonadPlus (Free1 c f) Source # | |
| type AlgebraType0 (Free1 c :: (Type -> Type) -> Type -> Type) (f :: l) Source # | |
Defined in Control.Algebra.Free | |
| type AlgebraType (Free1 c :: (Type -> Type) -> Type -> Type) (f :: Type -> Type) Source # | |
Defined in Control.Algebra.Free | |