| Copyright | (c) Justin Le 2019 | 
|---|---|
| License | BSD3 | 
| Maintainer | justin@jle.im | 
| Stability | experimental | 
| Portability | non-portable | 
| Safe Haskell | Safe-Inferred | 
| Language | Haskell2010 | 
Control.Monad.Freer.Church
Description
The church-encoded Freer Monad.  Basically provides the free monad in
 a way that is compatible with HFunctor and
 Interpret.  We also have the "semigroup" version
 Free1, which is the free  Bind.
The module also provides a version of :.: (or
 Compose), Comp, in a way that is compatible with
 HBifunctor and the related typeclasses.
Synopsis
- newtype Free f a = Free {- runFree :: forall r. (a -> r) -> (forall s. f s -> (s -> r) -> r) -> r
 
- reFree :: (MonadFree f m, Functor f) => Free f a -> m a
- liftFree :: f ~> Free f
- interpretFree :: Monad g => (f ~> g) -> Free f ~> g
- retractFree :: Monad f => Free f ~> f
- hoistFree :: (f ~> g) -> Free f ~> Free g
- foldFree :: Functor f => (a -> r) -> (f r -> r) -> Free f a -> r
- foldFree' :: (a -> r) -> (forall s. f s -> (s -> r) -> r) -> Free f a -> r
- foldFreeC :: (a -> r) -> (Coyoneda f r -> r) -> Free f a -> r
- newtype Free1 f a where
- reFree1 :: (MonadFree f m, Functor f) => Free1 f a -> m a
- toFree :: Free1 f ~> Free f
- liftFree1 :: f ~> Free1 f
- interpretFree1 :: Bind g => (f ~> g) -> Free1 f ~> g
- retractFree1 :: Bind f => Free1 f ~> f
- hoistFree1 :: (f ~> g) -> Free1 f ~> Free1 g
- free1Comp :: Free1 f ~> Comp f (Free f)
- matchFree1 :: forall f. Functor f => Free1 f ~> (f :+: Comp f (Free1 f))
- foldFree1 :: Functor f => (f a -> r) -> (f r -> r) -> Free1 f a -> r
- foldFree1' :: (forall s. f s -> (s -> a) -> r) -> (forall s. f s -> (s -> r) -> r) -> Free1 f a -> r
- foldFree1C :: (Coyoneda f a -> r) -> (Coyoneda f r -> r) -> Free1 f a -> r
- data Comp f g a where
- comp :: f (g a) -> Comp f g a
Free
A Free ff enhanced with "sequential binding" capabilities.
 It allows you to sequence multiple fs one after the other, and also to
 determine "what f to sequence" based on the result of the computation
 so far.
Essentially, you can think of this as "giving f a Monad instance",
 with all that that entails (return, >>=, etc.).
Lift f into it with inject :: f a -> Free
 f a
interpret::Monadg => (forall x. f x -> g x) ->Freef a -> g a
Structurally, this is equivalent to many "nested" f's.  A value of type
 Free f a
- a 
- f a 
- f (f a) 
- f (f (f a)) 
- .. etc.
Under the hood, this is the Church-encoded Freer monad.  It's
 Free, or F, but in
 a way that is compatible with HFunctor and
 Interpret.
Instances
Interpretation
Folding
Free1
The Free Bind.  Imbues any functor f with a Bind instance.
Conceptually, this is "Free without pure".  That is, while normally
 Free f aa, a f a, a f (f a), etc., a Free1 f af a, f (f a), f (f (f a)), etc.  It's a Free with "at least
 one layer of f", excluding the a case.
It can be useful as the semigroup formed by :.: (functor composition):
 Sometimes we want an f :.: f, or an f :.: f :.: f, or an f :.:
 f :.: f :.: f...just as long as we have at least one f.
Constructors
| Free1 | |
| Fields 
 | |
Bundled Patterns
| pattern DoneF1 :: Functor f => f a -> Free1 f a | Constructor matching on the case that a  | 
| pattern MoreF1 :: Functor f => f (Free1 f a) -> Free1 f a | Constructor matching on the case that a  As a constructor, this is equivalent to  | 
Instances
| HBind Free1 Source # | |
| Inject Free1 Source # | |
| FreeOf Bind Free1 Source # | |
| HFunctor Free1 Source # | |
| Bind f => Interpret Free1 (f :: Type -> Type) Source # | A free  | 
| Foldable f => Foldable (Free1 f) Source # | |
| Defined in Control.Monad.Freer.Church Methods fold :: Monoid m => Free1 f m -> m # foldMap :: Monoid m => (a -> m) -> Free1 f a -> m # foldMap' :: Monoid m => (a -> m) -> Free1 f a -> m # foldr :: (a -> b -> b) -> b -> Free1 f a -> b # foldr' :: (a -> b -> b) -> b -> Free1 f a -> b # foldl :: (b -> a -> b) -> b -> Free1 f a -> b # foldl' :: (b -> a -> b) -> b -> Free1 f a -> b # foldr1 :: (a -> a -> a) -> Free1 f a -> a # foldl1 :: (a -> a -> a) -> Free1 f a -> a # elem :: Eq a => a -> Free1 f a -> Bool # maximum :: Ord a => Free1 f a -> a # minimum :: Ord a => Free1 f a -> a # | |
| Foldable1 f => Foldable1 (Free1 f) Source # | |
| Defined in Control.Monad.Freer.Church Methods fold1 :: Semigroup m => Free1 f m -> m # foldMap1 :: Semigroup m => (a -> m) -> Free1 f a -> m # foldMap1' :: Semigroup m => (a -> m) -> Free1 f a -> m # toNonEmpty :: Free1 f a -> NonEmpty a # maximum :: Ord a => Free1 f a -> a # minimum :: Ord a => Free1 f a -> a # foldrMap1 :: (a -> b) -> (a -> b -> b) -> Free1 f a -> b # foldlMap1' :: (a -> b) -> (b -> a -> b) -> Free1 f a -> b # foldlMap1 :: (a -> b) -> (b -> a -> b) -> Free1 f a -> b # foldrMap1' :: (a -> b) -> (a -> b -> b) -> Free1 f a -> b # | |
| (Functor f, Eq1 f) => Eq1 (Free1 f) Source # | |
| (Functor f, Ord1 f) => Ord1 (Free1 f) Source # | |
| Defined in Control.Monad.Freer.Church | |
| (Functor f, Read1 f) => Read1 (Free1 f) Source # | |
| Defined in Control.Monad.Freer.Church | |
| (Functor f, Show1 f) => Show1 (Free1 f) Source # | |
| Traversable f => Traversable (Free1 f) Source # | |
| Defined in Control.Monad.Freer.Church | |
| Functor (Free1 f) Source # | |
| Invariant (Free1 f) Source # | Since: 0.4.1.2 | 
| Defined in Control.Monad.Freer.Church | |
| Apply (Free1 f) Source # | |
| Bind (Free1 f) Source # | |
| Traversable1 f => Traversable1 (Free1 f) Source # | |
| (Functor f, Read1 f, Read a) => Read (Free1 f a) Source # | |
| (Functor f, Show1 f, Show a) => Show (Free1 f a) Source # | |
| (Functor f, Eq1 f, Eq a) => Eq (Free1 f a) Source # | |
| (Functor f, Ord1 f, Ord a) => Ord (Free1 f a) Source # | |
| type FreeFunctorBy Free1 Source # | |
| Defined in Data.HFunctor.Final | |
Interpretation
Conversion
Folding
foldFree1' :: (forall s. f s -> (s -> a) -> r) -> (forall s. f s -> (s -> r) -> r) -> Free1 f a -> r Source #
Comp
Functor composition.  Comp f g af (g a), and
 the Comp pattern synonym is a way of getting the f (g a) in
 a Comp f g a
For example, Maybe (IO Bool)Comp Maybe IO Bool
This is mostly useful for its typeclass instances: in particular,
 Functor, Applicative, HBifunctor, and
 Monoidal.
This is essentially a version of :.: and
 Compose that allows for an
 HBifunctor instance.
It is slightly less performant.  Using comp . unCompComp value (if you have Functor f
The "free monoid" over Comp is Free, and the "free semigroup" over
 Comp is Free1.
Constructors
| forall x. (f x) :>>= (x -> g a) | 
Bundled Patterns
| pattern Comp :: Functor f => f (g a) -> Comp f g a | Pattern match on and construct a  | 
Instances
| HFunctor (Comp f :: (k -> Type) -> k -> Type) Source # | |
| HBifunctor (Comp :: (Type -> Type) -> (Type -> Type) -> Type -> Type) Source # | |
| Defined in Data.HFunctor.Internal Methods hleft :: forall (f :: k -> Type) (j :: k -> Type) (g :: k -> Type). (f ~> j) -> Comp f g ~> Comp j g Source # hright :: forall (g :: k -> Type) (l :: k -> Type) (f :: k -> Type). (g ~> l) -> Comp f g ~> Comp f l Source # hbimap :: forall (f :: k -> Type) (j :: k -> Type) (g :: k -> Type) (l :: k -> Type). (f ~> j) -> (g ~> l) -> Comp f g ~> Comp j l Source # | |
| Applicative f => Inject (Comp f :: (Type -> Type) -> Type -> Type) Source # | |
| Associative (Comp :: (Type -> Type) -> (Type -> Type) -> Type -> Type) Source # | |
| Defined in Data.HBifunctor.Associative Associated Types type NonEmptyBy Comp :: (Type -> Type) -> Type -> Type Source # type FunctorBy Comp :: (Type -> Type) -> Constraint Source # Methods associating :: forall (f :: Type -> Type) (g :: Type -> Type) (h :: Type -> Type). (FunctorBy Comp f, FunctorBy Comp g, FunctorBy Comp h) => Comp f (Comp g h) <~> Comp (Comp f g) h Source # appendNE :: forall (f :: Type -> Type). Comp (NonEmptyBy Comp f) (NonEmptyBy Comp f) ~> NonEmptyBy Comp f Source # matchNE :: forall (f :: Type -> Type). FunctorBy Comp f => NonEmptyBy Comp f ~> (f :+: Comp f (NonEmptyBy Comp f)) Source # consNE :: forall (f :: Type -> Type). Comp f (NonEmptyBy Comp f) ~> NonEmptyBy Comp f Source # toNonEmptyBy :: forall (f :: Type -> Type). Comp f f ~> NonEmptyBy Comp f Source # | |
| Bind f => SemigroupIn (Comp :: (Type -> Type) -> (Type -> Type) -> Type -> Type) f Source # | Instances of  | 
| Tensor (Comp :: (Type -> Type) -> (Type -> Type) -> Type -> Type) Identity Source # | |
| Defined in Data.HBifunctor.Tensor Methods intro1 :: forall (f :: Type -> Type). f ~> Comp f Identity Source # intro2 :: forall (g :: Type -> Type). g ~> Comp Identity g Source # elim1 :: forall (f :: Type -> Type). FunctorBy Comp f => Comp f Identity ~> f Source # elim2 :: forall (g :: Type -> Type). FunctorBy Comp g => Comp Identity g ~> g Source # appendLB :: forall (f :: Type -> Type). Comp (ListBy Comp f) (ListBy Comp f) ~> ListBy Comp f Source # splitNE :: forall (f :: Type -> Type). NonEmptyBy Comp f ~> Comp f (ListBy Comp f) Source # splittingLB :: forall (f :: Type -> Type). ListBy Comp f <~> (Identity :+: Comp f (ListBy Comp f)) Source # toListBy :: forall (f :: Type -> Type). Comp f f ~> ListBy Comp f Source # fromNE :: forall (f :: Type -> Type). NonEmptyBy Comp f ~> ListBy Comp f Source # | |
| (Bind f, Monad f) => MonoidIn (Comp :: (Type -> Type) -> (Type -> Type) -> Type -> Type) Identity f Source # | Instances of  This instance is the "proof" that "monads are the monoids in the
 category of endofunctors (enriched with  Note that because of typeclass constraints, this requires  | 
| (Foldable f, Foldable g) => Foldable (Comp f g) Source # | |
| Defined in Control.Monad.Freer.Church Methods fold :: Monoid m => Comp f g m -> m # foldMap :: Monoid m => (a -> m) -> Comp f g a -> m # foldMap' :: Monoid m => (a -> m) -> Comp f g a -> m # foldr :: (a -> b -> b) -> b -> Comp f g a -> b # foldr' :: (a -> b -> b) -> b -> Comp f g a -> b # foldl :: (b -> a -> b) -> b -> Comp f g a -> b # foldl' :: (b -> a -> b) -> b -> Comp f g a -> b # foldr1 :: (a -> a -> a) -> Comp f g a -> a # foldl1 :: (a -> a -> a) -> Comp f g a -> a # elem :: Eq a => a -> Comp f g a -> Bool # maximum :: Ord a => Comp f g a -> a # minimum :: Ord a => Comp f g a -> a # | |
| (Functor f, Eq1 f, Eq1 g) => Eq1 (Comp f g) Source # | |
| (Functor f, Ord1 f, Ord1 g) => Ord1 (Comp f g) Source # | |
| Defined in Control.Monad.Freer.Church | |
| (Functor f, Read1 f, Read1 g) => Read1 (Comp f g) Source # | |
| Defined in Control.Monad.Freer.Church | |
| (Functor f, Show1 f, Show1 g) => Show1 (Comp f g) Source # | |
| (Traversable f, Traversable g) => Traversable (Comp f g) Source # | |
| Defined in Control.Monad.Freer.Church | |
| (Alternative f, Alternative g) => Alternative (Comp f g) Source # | |
| (Applicative f, Applicative g) => Applicative (Comp f g) Source # | |
| Functor g => Functor (Comp f g) Source # | |
| Invariant g => Invariant (Comp f g) Source # | Since: 0.4.1.2 | 
| Defined in Control.Monad.Freer.Church | |
| (Alt f, Alt g) => Alt (Comp f g) Source # | Since: 0.3.6.0 | 
| (Apply f, Apply g) => Apply (Comp f g) Source # | Since: 0.3.6.0 | 
| Functor f => Apply (Chain1 (Comp :: (Type -> Type) -> (Type -> Type) -> Type -> Type) f) Source # | |
| Defined in Data.HFunctor.Chain | |
| Functor f => Bind (Chain1 (Comp :: (Type -> Type) -> (Type -> Type) -> Type -> Type) f) Source # | 
 | 
| (Plus f, Plus g) => Plus (Comp f g) Source # | Since: 0.3.6.0 | 
| Defined in Control.Monad.Freer.Church | |
| (Functor f, Read1 f, Read1 g, Read a) => Read (Comp f g a) Source # | |
| (Functor f, Show1 f, Show1 g, Show a) => Show (Comp f g a) Source # | |
| (Functor f, Eq1 f, Eq1 g, Eq a) => Eq (Comp f g a) Source # | |
| (Functor f, Ord1 f, Ord1 g, Ord a) => Ord (Comp f g a) Source # | |
| Defined in Control.Monad.Freer.Church | |
| Applicative (Chain (Comp :: (Type -> Type) -> (Type -> Type) -> Type -> Type) Identity f) Source # | |
| Defined in Data.HFunctor.Chain Methods pure :: a -> Chain Comp Identity f a # (<*>) :: Chain Comp Identity f (a -> b) -> Chain Comp Identity f a -> Chain Comp Identity f b # liftA2 :: (a -> b -> c) -> Chain Comp Identity f a -> Chain Comp Identity f b -> Chain Comp Identity f c # (*>) :: Chain Comp Identity f a -> Chain Comp Identity f b -> Chain Comp Identity f b # (<*) :: Chain Comp Identity f a -> Chain Comp Identity f b -> Chain Comp Identity f a # | |
| Monad (Chain (Comp :: (Type -> Type) -> (Type -> Type) -> Type -> Type) Identity f) Source # | 
 | 
| Apply (Chain (Comp :: (Type -> Type) -> (Type -> Type) -> Type -> Type) Identity f) Source # | |
| Defined in Data.HFunctor.Chain Methods (<.>) :: Chain Comp Identity f (a -> b) -> Chain Comp Identity f a -> Chain Comp Identity f b # (.>) :: Chain Comp Identity f a -> Chain Comp Identity f b -> Chain Comp Identity f b # (<.) :: Chain Comp Identity f a -> Chain Comp Identity f b -> Chain Comp Identity f a # liftF2 :: (a -> b -> c) -> Chain Comp Identity f a -> Chain Comp Identity f b -> Chain Comp Identity f c # | |
| Bind (Chain (Comp :: (Type -> Type) -> (Type -> Type) -> Type -> Type) Identity f) Source # | |
| type FunctorBy (Comp :: (Type -> Type) -> (Type -> Type) -> Type -> Type) Source # | |
| type NonEmptyBy (Comp :: (Type -> Type) -> (Type -> Type) -> Type -> Type) Source # | |
| Defined in Data.HBifunctor.Associative | |
| type ListBy (Comp :: (Type -> Type) -> (Type -> Type) -> Type -> Type) Source # | |