| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Control.Alternative.Free.LZLC
Description
Free alternative (with left zero + left catch).
Alternative laws were not set to one, clear definition,
but there are two major ones.
For an instance of (Alternative f), both laws have these in common.
- Inherited laws from
Applicative (f a,forms monoid for any typeempty,<|>)a.- Left zero law:
.empty<*>x ===empty
Candidate #1 of the Alternative law have Left distribution law.
-- Left distribution (x<|>y)<*>z === (x <*> z) <|> (y <*> z)
Another candidate #2 have Left catch law instead.
-- Left catchpurex<|>y === pure x
Reference Typeclassopedia https://wiki.haskell.org/Typeclassopedia#Laws_6 for more about these laws.
The "free alternative" construction for the alternative #1 (with Left distribution) is known and implemented.
- https://people.cs.kuleuven.be/~tom.schrijvers/Research/talks/ppdp2015.pdf
- https://hackage.haskell.org/package/free-5.2/docs/Control-Alternative-Free.html
This module provides the free alternative #2.
Synopsis
- data Free (f :: Type -> Type) a where
- FreeTrivial :: forall (f :: Type -> Type) a. Trivial f a -> Free f a
- FreeSumZOf' :: forall (f :: Type -> Type) a. NontrivialSumZ (Summand f) a -> Free f a
- FreeApZOf' :: forall (f :: Type -> Type) a. NontrivialApZ (Factor f) a -> Free f a
- pattern SumZOf :: SumZ (Summand f) a -> Free f a
- pattern ApZOf :: Functor f => ApZ (Factor f) a -> Free f a
- newtype Summand (f :: Type -> Type) a = Summand {
- runSummand :: Either (f a) (NontrivialApZ (Factor f) a)
- viewSummand :: Summand f a -> Either (f a) (ApZ (Factor f) a)
- newtype Factor (f :: Type -> Type) a = Factor {
- runFactor :: Either (f a) (NontrivialSumZ (Summand f) a)
- viewFactor :: Factor f a -> Either (f a) (SumZ (Summand f) a)
- viewSumZ :: forall (f :: Type -> Type) a. Free f a -> SumZ (Summand f) a
- reviewSumZ :: forall (f :: Type -> Type) a. SumZ (Summand f) a -> Free f a
- viewApZ :: forall (f :: Type -> Type) a. Free f a -> ApZ (Factor f) a
- reviewApZ :: forall (f :: Type -> Type) a. Functor f => ApZ (Factor f) a -> Free f a
- hoistFree :: (forall x. f x -> g x) -> Free f a -> Free g a
- liftFree :: f a -> Free f a
- foldFree :: forall f g a. Alternative g => (forall x. f x -> g x) -> Free f a -> g a
- data Trivial (f :: Type -> Type) a
- = TrivialZero
- | TrivialPure a
- | TrivialLift (f a)
- type SumZ (f :: Type -> Type) a = ListZ a (f a)
- data NontrivialSumZ (f :: Type -> Type) a
- data NontrivialApZ (f :: Type -> Type) a where
- ApZero :: forall (f :: Type -> Type) a1 a. f a1 -> NontrivialApZ f a
- ApMany :: forall (f :: Type -> Type) a1 b a. f a1 -> f b -> ApZ f (b -> a1 -> a) -> NontrivialApZ f a
Type definitions
data Free (f :: Type -> Type) a where Source #
The Free (left zero + left catch) Alternative.
The constructors of Free is named intentionally verbose.
To construct a value of Free f a, a convenient and recommended
way is to use liftFree and methods of Alternative (Free f) instances.
To pattern match a value of Free f a, a convenient and recommended
way is to use ApZOf and SumZOf pattern synonyms, along with
viewFactor and viewSummand to pattern match on Factor and Summand
further.
Constructors
| FreeTrivial :: forall (f :: Type -> Type) a. Trivial f a -> Free f a | |
| FreeSumZOf' :: forall (f :: Type -> Type) a. NontrivialSumZ (Summand f) a -> Free f a | |
| FreeApZOf' :: forall (f :: Type -> Type) a. NontrivialApZ (Factor f) a -> Free f a |
Bundled Patterns
| pattern SumZOf :: SumZ (Summand f) a -> Free f a | View |
| pattern ApZOf :: Functor f => ApZ (Factor f) a -> Free f a | View |
newtype Summand (f :: Type -> Type) a Source #
Constructors
| Summand | |
Fields
| |
newtype Factor (f :: Type -> Type) a Source #
Constructors
| Factor | |
Fields
| |
Universal properties
foldFree :: forall f g a. Alternative g => (forall x. f x -> g x) -> Free f a -> g a Source #
Auxiliary definitions
data Trivial (f :: Type -> Type) a Source #
Trivial expressions
Constructors
| TrivialZero | |
| TrivialPure a | |
| TrivialLift (f a) |
type SumZ (f :: Type -> Type) a = ListZ a (f a) Source #
Formal sum of f a ending in either pure a (Zee a) or empty (Nil).
data NontrivialSumZ (f :: Type -> Type) a Source #
Trivial f a + NontrivialSumZ f a ~ SumZ f a = ListZ a (f a)
Instances
| FFunctor NontrivialSumZ Source # | |
Defined in Control.Alternative.Free.LZLC | |
| Functor f => Functor (NontrivialSumZ f) Source # | |
Defined in Control.Alternative.Free.LZLC Methods fmap :: (a -> b) -> NontrivialSumZ f a -> NontrivialSumZ f b # (<$) :: a -> NontrivialSumZ f b -> NontrivialSumZ f a # | |
data NontrivialApZ (f :: Type -> Type) a where Source #
Trivial f a + NontrivialApZ f a ~ ApZ f a
Constructors
| ApZero :: forall (f :: Type -> Type) a1 a. f a1 -> NontrivialApZ f a | |
| ApMany :: forall (f :: Type -> Type) a1 b a. f a1 -> f b -> ApZ f (b -> a1 -> a) -> NontrivialApZ f a |
Instances
| FFunctor NontrivialApZ Source # | |
Defined in Control.Alternative.Free.LZLC | |
| Functor (NontrivialApZ f) Source # | |
Defined in Control.Alternative.Free.LZLC Methods fmap :: (a -> b) -> NontrivialApZ f a -> NontrivialApZ f b # (<$) :: a -> NontrivialApZ f b -> NontrivialApZ f a # | |