| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Yaya.Fold
Synopsis
- type Algebra c f a = f a `c` a
- type GAlgebra c w f a = f (w a) `c` a
- type ElgotAlgebra c w f a = w (f a) `c` a
- type AlgebraM c m f a = f a `c` m a
- type GAlgebraM c m w f a = f (w a) `c` m a
- type ElgotAlgebraM c m w f a = w (f a) `c` m a
- type Coalgebra c f a = a `c` f a
- type GCoalgebra c m f a = a `c` f (m a)
- type ElgotCoalgebra c m f a = a `c` m (f a)
- type CoalgebraM c m f a = a `c` m (f a)
- type GCoalgebraM c m n f a = a `c` m (f (n a))
- class Projectable c t f | t -> f where
- class Projectable c t f => Steppable c t f | t -> f where
- class Recursive c t f | t -> f where
- class Corecursive c t f | t -> f where
- recursiveEq :: (Recursive (->) t f, Steppable (->) u f, Functor f, Foldable f, Eq1 f) => t -> u -> Bool
- recursiveShowsPrec :: (Recursive (->) t f, Show1 f) => Int -> t -> ShowS
- data Mu f = Mu (forall a. Algebra (->) f a -> a)
- data Nu f where
- zipAlgebras :: Functor f => Algebra (->) f a -> Algebra (->) f b -> Algebra (->) f (a, b)
- lowerDay :: Projectable (->) t g => Algebra (->) (Day f g) a -> Algebra (->) f (t -> a)
- cata2 :: (Recursive (->) t f, Projectable (->) u g) => Algebra (->) (Day f g) a -> t -> u -> a
- lowerAlgebra :: (Functor f, Comonad w) => DistributiveLaw (->) f w -> GAlgebra (->) w f a -> Algebra (->) f (w a)
- lowerAlgebraM :: (Applicative m, Traversable f, Comonad w, Traversable w) => DistributiveLaw (->) f w -> GAlgebraM (->) m w f a -> AlgebraM (->) m f (w a)
- lowerCoalgebra :: (Functor f, Monad m) => DistributiveLaw (->) m f -> GCoalgebra (->) m f a -> Coalgebra (->) f (m a)
- lowerCoalgebraM :: (Applicative m, Traversable f, Monad n, Traversable n) => DistributiveLaw (->) n f -> GCoalgebraM (->) m n f a -> CoalgebraM (->) m f (n a)
- gcata :: (Recursive (->) t f, Functor f, Comonad w) => DistributiveLaw (->) f w -> GAlgebra (->) w f a -> t -> a
- elgotCata :: (Recursive (->) t f, Functor f, Comonad w) => DistributiveLaw (->) f w -> ElgotAlgebra (->) w f a -> t -> a
- gcataM :: (Monad m, Recursive (->) t f, Traversable f, Comonad w, Traversable w) => DistributiveLaw (->) f w -> GAlgebraM (->) m w f a -> t -> m a
- elgotCataM :: (Monad m, Recursive (->) t f, Traversable f, Comonad w, Traversable w) => DistributiveLaw (->) f w -> ElgotAlgebraM (->) m w f a -> t -> m a
- ezygoM :: (Monad m, Recursive (->) t f, Traversable f) => AlgebraM (->) m f b -> ElgotAlgebraM (->) m ((,) b) f a -> t -> m a
- gana :: (Corecursive (->) t f, Functor f, Monad m) => DistributiveLaw (->) m f -> GCoalgebra (->) m f a -> a -> t
- elgotAna :: (Corecursive (->) t f, Functor f, Monad m) => DistributiveLaw (->) m f -> ElgotCoalgebra (->) m f a -> a -> t
- lambek :: (Steppable (->) t f, Recursive (->) t f, Functor f) => Coalgebra (->) f t
- colambek :: (Projectable (->) t f, Corecursive (->) t f, Functor f) => Algebra (->) f t
- type DistributiveLaw c f g = forall a. f (g a) `c` g (f a)
- distIdentity :: Functor f => DistributiveLaw (->) f Identity
- seqIdentity :: Functor f => DistributiveLaw (->) Identity f
- distTuple :: Functor f => Algebra (->) f a -> DistributiveLaw (->) f ((,) a)
- distEnvT :: Functor f => Algebra (->) f a -> DistributiveLaw (->) f w -> DistributiveLaw (->) f (EnvT a w)
- seqEither :: Functor f => Coalgebra (->) f a -> DistributiveLaw (->) (Either a) f
- attributeAlgebra :: (Steppable (->) t (EnvT a f), Functor f) => Algebra (->) f a -> Algebra (->) f t
- attributeCoalgebra :: Coalgebra (->) f a -> Coalgebra (->) (EnvT a f) a
- ignoringAttribute :: Algebra (->) f a -> Algebra (->) (EnvT b f) a
- unFree :: Steppable (->) t f => Algebra (->) (FreeF f t) t
- constEmbed :: Algebra (->) (Const a) a
- constProject :: Coalgebra (->) (Const a) a
- constCata :: Algebra (->) (Const b) a -> b -> a
- constAna :: Coalgebra (->) (Const b) a -> a -> b
- type BialgebraIso f a = Iso' (f a) a
- type AlgebraPrism f a = Prism' (f a) a
- type CoalgebraPrism f a = Prism' a (f a)
- steppableIso :: Steppable (->) t f => BialgebraIso f t
- birecursiveIso :: (Recursive (->) t f, Corecursive (->) t f) => BialgebraIso f a -> Iso' t a
- recursivePrism :: (Recursive (->) t f, Corecursive (->) t f, Traversable f) => AlgebraPrism f a -> Prism' t a
Documentation
type ElgotAlgebra c w f a = w (f a) `c` a Source #
type ElgotAlgebraM c m w f a = w (f a) `c` m a Source #
type GCoalgebra c m f a = a `c` f (m a) Source #
type ElgotCoalgebra c m f a = a `c` m (f a) Source #
type CoalgebraM c m f a = a `c` m (f a) Source #
Note that using a CoalgebraM “directly” is partial (e.g., with
anaM). However, ana . Compose can accept a CoalgebraM
and produce something like an effectful stream.
type GCoalgebraM c m n f a = a `c` m (f (n a)) Source #
class Projectable c t f | t -> f where Source #
This type class is lawless on its own, but there exist types that can’t
implement the corresponding embed operation. Laws are induced by
implementing either Steppable (which extends this) or Corecursive
(which doesn’t).
Instances
class Projectable c t f => Steppable c t f | t -> f where Source #
Structures you can walk through step-by-step.
Instances
class Recursive c t f | t -> f where Source #
Inductive structures that can be reasoned about in the way we usually do – with pattern matching.
Instances
| Recursive ((->) :: Type -> Type -> Type) Natural Maybe Source # | |
| Recursive ((->) :: Type -> Type -> Type) Void Identity Source # | |
| Recursive ((->) :: Type -> Type -> Type) (Mu f :: Type) (f :: Type -> Type) Source # | |
| Recursive ((->) :: Type -> Type -> Type) (Maybe a :: Type) (Const (Maybe a) :: Type -> Type) Source # | |
| Recursive ((->) :: Type -> Type -> Type) (Either a b :: Type) (Const (Either a b) :: Type -> Type) Source # | |
class Corecursive c t f | t -> f where Source #
Coinductive (potentially-infinite) structures that guarantee _productivity_ rather than termination.
Instances
| Corecursive ((->) :: Type -> Type -> Type) (Nu f :: Type) (f :: Type -> Type) Source # | |
| Functor f => Corecursive ((->) :: Type -> Type -> Type) (Fix f :: Type) (f :: Type -> Type) Source # | |
| Corecursive ((->) :: Type -> Type -> Type) ([a] :: Type) (XNor a :: Type -> Type) Source # | |
| Corecursive ((->) :: Type -> Type -> Type) (NonEmpty a :: Type) (AndMaybe a :: Type -> Type) Source # | |
| Corecursive ((->) :: Type -> Type -> Type) (Maybe a :: Type) (Const (Maybe a) :: Type -> Type) Source # | |
| Corecursive ((->) :: Type -> Type -> Type) (Either a b :: Type) (Const (Either a b) :: Type -> Type) Source # | |
| Functor f => Corecursive ((->) :: Type -> Type -> Type) (Cofree f a :: Type) (EnvT a f :: Type -> Type) Source # | |
| Functor f => Corecursive ((->) :: Type -> Type -> Type) (Free f a :: Type) (FreeF f a :: Type -> Type) Source # | |
recursiveEq :: (Recursive (->) t f, Steppable (->) u f, Functor f, Foldable f, Eq1 f) => t -> u -> Bool Source #
A fixed-point operator for inductive / finite data structures.
- NB*: This is only guaranteed to be finite when
f ais strict ina(having strict functors won't preventNufrom being lazy). Using-XStrictDatacan help with this a lot.
Instances
| DFunctor Mu Source # | |
| (Functor f, Foldable f, Eq1 f) => Eq (Mu f) Source # | |
| Show1 f => Show (Mu f) Source # | |
| Recursive ((->) :: Type -> Type -> Type) (Mu f :: Type) (f :: Type -> Type) Source # | |
| Functor f => Projectable ((->) :: Type -> Type -> Type) (Mu f :: Type) (f :: Type -> Type) Source # | |
| Functor f => Steppable ((->) :: Type -> Type -> Type) (Mu f :: Type) (f :: Type -> Type) Source # | |
A fixed-point operator for coinductive / potentially-infinite data structures.
Instances
| DFunctor Nu Source # | |
| Corecursive ((->) :: Type -> Type -> Type) (Nu f :: Type) (f :: Type -> Type) Source # | |
| Functor f => Projectable ((->) :: Type -> Type -> Type) (Nu f :: Type) (f :: Type -> Type) Source # | |
| Functor f => Steppable ((->) :: Type -> Type -> Type) (Nu f :: Type) (f :: Type -> Type) Source # | |
lowerDay :: Projectable (->) t g => Algebra (->) (Day f g) a -> Algebra (->) f (t -> a) Source #
Algebras over Day convolution are convenient for binary operations, but
aren’t directly handleable by cata.
cata2 :: (Recursive (->) t f, Projectable (->) u g) => Algebra (->) (Day f g) a -> t -> u -> a Source #
lowerAlgebra :: (Functor f, Comonad w) => DistributiveLaw (->) f w -> GAlgebra (->) w f a -> Algebra (->) f (w a) Source #
lowerAlgebraM :: (Applicative m, Traversable f, Comonad w, Traversable w) => DistributiveLaw (->) f w -> GAlgebraM (->) m w f a -> AlgebraM (->) m f (w a) Source #
lowerCoalgebra :: (Functor f, Monad m) => DistributiveLaw (->) m f -> GCoalgebra (->) m f a -> Coalgebra (->) f (m a) Source #
Makes it possible to provide a GCoalgebra to ana.
lowerCoalgebraM :: (Applicative m, Traversable f, Monad n, Traversable n) => DistributiveLaw (->) n f -> GCoalgebraM (->) m n f a -> CoalgebraM (->) m f (n a) Source #
Makes it possible to provide a GCoalgebraM to anaM.
gcata :: (Recursive (->) t f, Functor f, Comonad w) => DistributiveLaw (->) f w -> GAlgebra (->) w f a -> t -> a Source #
elgotCata :: (Recursive (->) t f, Functor f, Comonad w) => DistributiveLaw (->) f w -> ElgotAlgebra (->) w f a -> t -> a Source #
gcataM :: (Monad m, Recursive (->) t f, Traversable f, Comonad w, Traversable w) => DistributiveLaw (->) f w -> GAlgebraM (->) m w f a -> t -> m a Source #
elgotCataM :: (Monad m, Recursive (->) t f, Traversable f, Comonad w, Traversable w) => DistributiveLaw (->) f w -> ElgotAlgebraM (->) m w f a -> t -> m a Source #
ezygoM :: (Monad m, Recursive (->) t f, Traversable f) => AlgebraM (->) m f b -> ElgotAlgebraM (->) m ((,) b) f a -> t -> m a Source #
gana :: (Corecursive (->) t f, Functor f, Monad m) => DistributiveLaw (->) m f -> GCoalgebra (->) m f a -> a -> t Source #
elgotAna :: (Corecursive (->) t f, Functor f, Monad m) => DistributiveLaw (->) m f -> ElgotCoalgebra (->) m f a -> a -> t Source #
colambek :: (Projectable (->) t f, Corecursive (->) t f, Functor f) => Algebra (->) f t Source #
type DistributiveLaw c f g = forall a. f (g a) `c` g (f a) Source #
There are a number of distributive laws, including
sequenceA, distribute, and
sequenceL. Yaya also provides others for specific recursion
schemes.
distIdentity :: Functor f => DistributiveLaw (->) f Identity Source #
A less-constrained distribute for Identity.
seqIdentity :: Functor f => DistributiveLaw (->) Identity f Source #
distEnvT :: Functor f => Algebra (->) f a -> DistributiveLaw (->) f w -> DistributiveLaw (->) f (EnvT a w) Source #
attributeAlgebra :: (Steppable (->) t (EnvT a f), Functor f) => Algebra (->) f a -> Algebra (->) f t Source #
Converts an Algebra to one that annotates the tree with the result for
each node.
attributeCoalgebra :: Coalgebra (->) f a -> Coalgebra (->) (EnvT a f) a Source #
Converts a Coalgebra to one that annotates the tree with the seed that
generated each node.
ignoringAttribute :: Algebra (->) f a -> Algebra (->) (EnvT b f) a Source #
This is just a more obvious name for composing lowerEnvT with your
algebra directly.
unFree :: Steppable (->) t f => Algebra (->) (FreeF f t) t Source #
It is somewhat common to have a natural transformation that looks like
η :: forall a. f a -> Free g a. This maps naturally to a GCoalgebra (to
pass to apo) with η . project, but the desired Algebra is
more likely to be cata unFree . η than embed . η. See yaya-streams for
some examples of this.
instances for non-recursive types
constEmbed :: Algebra (->) (Const a) a Source #
constProject :: Coalgebra (->) (Const a) a Source #
Optics
type BialgebraIso f a = Iso' (f a) a Source #
type AlgebraPrism f a = Prism' (f a) a Source #
type CoalgebraPrism f a = Prism' a (f a) Source #
steppableIso :: Steppable (->) t f => BialgebraIso f t Source #
birecursiveIso :: (Recursive (->) t f, Corecursive (->) t f) => BialgebraIso f a -> Iso' t a Source #
recursivePrism :: (Recursive (->) t f, Corecursive (->) t f, Traversable f) => AlgebraPrism f a -> Prism' t a Source #