Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Synopsis
- type Algebra c f a = f a `c` a
- type AlgebraM c m f a = f a `c` m a
- type AlgebraPrism f a = Prism' (f a) a
- type BialgebraIso f a = Iso' (f a) a
- type Coalgebra c f a = a `c` f a
- type CoalgebraM c m f a = a `c` m (f a)
- type CoalgebraPrism f a = Prism' a (f a)
- class Corecursive c t f | t -> f where
- type DistributiveLaw c f g = forall a. f (g a) `c` g (f a)
- type ElgotAlgebra c w f a = w (f a) `c` a
- type ElgotAlgebraM c m w f a = w (f a) `c` m a
- type ElgotCoalgebra c m f a = a `c` m (f a)
- type GAlgebra c w f a = f (w a) `c` a
- type GAlgebraM c m w f a = f (w a) `c` m a
- type GCoalgebra c m f a = a `c` f (m a)
- type GCoalgebraM c m n f a = a `c` m (f (n a))
- newtype Mu f = Mu (forall a. Algebra (->) f a -> a)
- data Nu f where
- class Projectable c t f | t -> f where
- class Recursive c t f | t -> f where
- class Projectable c t f => Steppable c t f | t -> f where
- attributeAlgebra :: (Steppable (->) t (EnvT a f), Functor f) => Algebra (->) f a -> Algebra (->) f t
- attributeCoalgebra :: Coalgebra (->) f a -> Coalgebra (->) (EnvT a f) a
- birecursiveIso :: (Recursive (->) t f, Corecursive (->) t f) => BialgebraIso f a -> Iso' t a
- cata2 :: (Recursive (->) t f, Projectable (->) u g) => Algebra (->) (Day f g) a -> t -> u -> a
- colambek :: (Projectable (->) t f, Corecursive (->) t f, Functor f) => Algebra (->) f t
- constAna :: Coalgebra (->) (Const b) a -> a -> b
- constCata :: Algebra (->) (Const b) a -> b -> a
- constEmbed :: Algebra (->) (Const a) a
- constProject :: Coalgebra (->) (Const a) a
- distEnvT :: Functor f => Algebra (->) f a -> DistributiveLaw (->) f w -> DistributiveLaw (->) f (EnvT a w)
- distIdentity :: Functor f => DistributiveLaw (->) f Identity
- distTuple :: Functor f => Algebra (->) f a -> DistributiveLaw (->) f (Pair a)
- elgotAna :: (Corecursive (->) t f, Functor f, Monad m) => DistributiveLaw (->) m f -> ElgotCoalgebra (->) m f a -> a -> t
- elgotCata :: (Recursive (->) t f, Functor f, Comonad w) => DistributiveLaw (->) f w -> ElgotAlgebra (->) w f a -> t -> 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 (Pair b) f a -> t -> m a
- gana :: (Corecursive (->) t f, Functor f, Monad m) => DistributiveLaw (->) m f -> GCoalgebra (->) m f a -> a -> t
- gcata :: (Recursive (->) t f, Functor f, Comonad w) => DistributiveLaw (->) f w -> GAlgebra (->) 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
- ignoringAttribute :: Algebra (->) f a -> Algebra (->) (EnvT b f) a
- lambek :: (Steppable (->) t f, Recursive (->) t f, Functor f) => Coalgebra (->) f t
- 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)
- lowerDay :: Projectable (->) t g => Algebra (->) (Day f g) a -> Algebra (->) f (t -> a)
- recursiveCompare :: (Recursive (->) t f, Steppable (->) u f, Functor f, Foldable f, Ord1 f) => t -> u -> Ordering
- recursiveCompare' :: (Recursive (->) t f, Steppable (->) u f, Functor f, Foldable f) => (f () -> f () -> Ordering) -> t -> u -> Ordering
- recursiveEq :: (Recursive (->) t f, Steppable (->) u f, Functor f, Foldable f, Eq1 f) => t -> u -> Bool
- recursiveEq' :: (Recursive (->) t f, Steppable (->) u f, Functor f, Foldable f) => (f () -> f () -> Bool) -> t -> u -> Bool
- recursivePrism :: (Recursive (->) t f, Corecursive (->) t f, Traversable f) => AlgebraPrism f a -> Prism' t a
- recursiveShowsPrec :: (Recursive (->) t f, Show1 f) => Int -> t -> ShowS
- recursiveShowsPrec' :: Recursive (->) t f => Algebra (->) f (Int -> ShowS) -> Int -> t -> ShowS
- seqEither :: Functor f => Coalgebra (->) f a -> DistributiveLaw (->) (Either a) f
- seqIdentity :: Functor f => DistributiveLaw (->) Identity f
- steppableIso :: Steppable (->) t f => BialgebraIso f t
- steppableReadPrec :: (Steppable (->) t f, Read1 f) => ReadPrec t
- steppableReadPrec' :: Steppable (->) t f => (ReadPrec t -> ReadPrec [t] -> ReadPrec (f t)) -> ReadPrec t
- unFree :: Steppable (->) t f => Algebra (->) (FreeF f t) t
- zipAlgebraMs :: (Applicative m, Functor f) => AlgebraM (->) m f a -> AlgebraM (->) m f b -> AlgebraM (->) m f (Pair a b)
- zipAlgebras :: Functor f => Algebra (->) f a -> Algebra (->) f b -> Algebra (->) f (Pair a b)
Documentation
type AlgebraPrism f a = Prism' (f a) a Source #
type BialgebraIso f a = Iso' (f a) 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 CoalgebraPrism f a = Prism' a (f a) Source #
class Corecursive c t f | t -> f where Source #
Coinductive (potentially-infinite) structures that guarantee _productivity_ rather than termination.
Instances
Corecursive (->) (Nu f :: Type) (f :: Type -> Type) Source # | |
Functor f => Corecursive (->) (Cofix f :: Type) (f :: Type -> Type) Source # | |
Corecursive (->) (NonEmpty a :: Type) (AndMaybe a :: Type -> Type) Source # | |
Corecursive (->) ([a] :: Type) (XNor a :: Type -> Type) Source # | |
Corecursive (->) (Maybe a :: Type) (Const (Maybe a) :: Type -> Type) Source # | |
Functor f => Corecursive (->) (Cofree f a :: Type) (EnvT a f :: Type -> Type) Source # | |
Functor f => Corecursive (->) (Free f a :: Type) (FreeF f a :: Type -> Type) Source # | |
Corecursive (->) (Either a b :: Type) (Const (Either a b) :: Type -> Type) 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.
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 ElgotCoalgebra c m f a = a `c` m (f a) Source #
type GCoalgebra c m f a = a `c` f (m a) Source #
type GCoalgebraM c m n f a = a `c` m (f (n a)) Source #
A fixed-point operator for inductive / finite data structures.
NB: This is only guaranteed to be finite when f a
is strict in a
(having strict functors won't prevent Nu
from being lazy). Using
-XStrictData
can help with this a lot.
Instances
DFunctor Mu Source # | |
Functor f => Projectable (->) (Mu f :: Type) (f :: Type -> Type) Source # | |
Recursive (->) (Mu f :: Type) (f :: Type -> Type) Source # | |
Functor f => Steppable (->) (Mu f :: Type) (f :: Type -> Type) Source # | |
Monoid (Mu (XNor a)) Source # | |
Semigroup (Mu (XNor a)) Source # | |
(Functor f, Read1 f) => Read (Mu f) Source # | Since: 0.6.1.0 |
Show1 f => Show (Mu f) Source # | |
(Functor f, Foldable f, Eq1 f) => Eq (Mu f) Source # | |
(Functor f, Foldable f, Ord1 f) => Ord (Mu f) Source # | Since: 0.6.1.0 |
A fixed-point operator for coinductive / potentially-infinite data structures.
Instances
DFunctor Nu Source # | |
Corecursive (->) (Nu f :: Type) (f :: Type -> Type) Source # | |
Functor f => Projectable (->) (Nu f :: Type) (f :: Type -> Type) Source # | |
Functor f => Steppable (->) (Nu f :: Type) (f :: Type -> Type) Source # | |
IsList (Nu (XNor a)) Source # | This instance is safe, since both structures are lazy. |
(Functor f, Read1 f) => Read (Nu f) Source # | Since: 0.6.1.0 |
type Item (Nu (XNor a)) Source # | |
Defined in Yaya.Applied |
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
Projectable (->) Void Identity Source # | |
Projectable (->) Natural Maybe Source # | |
Functor f => Projectable (->) (Mu f :: Type) (f :: Type -> Type) Source # | |
Functor f => Projectable (->) (Nu f :: Type) (f :: Type -> Type) Source # | |
Projectable (->) (Fix f :: Type) (f :: Type -> Type) Source # | |
Projectable (->) (Cofix f :: Type) (f :: Type -> Type) Source # | |
Projectable (->) (NonEmpty a :: Type) (AndMaybe a :: Type -> Type) Source # | |
Projectable (->) ([a] :: Type) (XNor a :: Type -> Type) Source # | |
Projectable (->) (Maybe a :: Type) (Const (Maybe a) :: Type -> Type) Source # | |
Projectable (->) (Cofree f a :: Type) (EnvT a f :: Type -> Type) Source # | |
Projectable (->) (Free f a :: Type) (FreeF f a :: Type -> Type) Source # | |
Projectable (->) (Either a b :: Type) (Const (Either a b) :: Type -> Type) Source # | |
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 (->) Void Identity Source # | |
Recursive (->) Natural Maybe Source # | |
Recursive (->) (Mu f :: Type) (f :: Type -> Type) Source # | |
Functor f => Recursive (->) (Fix f :: Type) (f :: Type -> Type) Source # | |
Recursive (->) (Maybe a :: Type) (Const (Maybe a) :: Type -> Type) Source # | |
Recursive (->) (Either a b :: Type) (Const (Either a b) :: Type -> Type) Source # | |
class Projectable c t f => Steppable c t f | t -> f where Source #
Structures you can walk through step-by-step.
Instances
Steppable (->) Void Identity Source # | |
Steppable (->) Natural Maybe Source # | |
Functor f => Steppable (->) (Mu f :: Type) (f :: Type -> Type) Source # | |
Functor f => Steppable (->) (Nu f :: Type) (f :: Type -> Type) Source # | |
Steppable (->) (Fix f :: Type) (f :: Type -> Type) Source # | |
Steppable (->) (Cofix f :: Type) (f :: Type -> Type) Source # | |
Steppable (->) (NonEmpty a :: Type) (AndMaybe a :: Type -> Type) Source # | |
Steppable (->) ([a] :: Type) (XNor a :: Type -> Type) Source # | |
Steppable (->) (Maybe a :: Type) (Const (Maybe a) :: Type -> Type) Source # | |
Steppable (->) (Cofree f a :: Type) (EnvT a f :: Type -> Type) Source # | |
Steppable (->) (Free f a :: Type) (FreeF f a :: Type -> Type) Source # | |
Steppable (->) (Either a b :: Type) (Const (Either a b) :: Type -> Type) 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.
birecursiveIso :: (Recursive (->) t f, Corecursive (->) t f) => BialgebraIso f a -> Iso' t a Source #
cata2 :: (Recursive (->) t f, Projectable (->) u g) => Algebra (->) (Day f g) a -> t -> u -> a Source #
colambek :: (Projectable (->) t f, Corecursive (->) t f, Functor f) => Algebra (->) f t Source #
constEmbed :: Algebra (->) (Const a) a Source #
constProject :: Coalgebra (->) (Const a) a Source #
distEnvT :: Functor f => Algebra (->) f a -> DistributiveLaw (->) f w -> DistributiveLaw (->) f (EnvT a w) Source #
distIdentity :: Functor f => DistributiveLaw (->) f Identity Source #
A less-constrained distribute
for Identity
.
elgotAna :: (Corecursive (->) t f, Functor f, Monad m) => DistributiveLaw (->) m f -> ElgotCoalgebra (->) m f a -> a -> t Source #
elgotCata :: (Recursive (->) t f, Functor f, Comonad w) => DistributiveLaw (->) f w -> ElgotAlgebra (->) w f a -> t -> 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 (Pair 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 #
gcata :: (Recursive (->) t f, Functor f, Comonad w) => DistributiveLaw (->) f w -> GAlgebra (->) 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 #
ignoringAttribute :: Algebra (->) f a -> Algebra (->) (EnvT b f) a Source #
This is just a more obvious name for composing lowerEnvT
with your
algebra directly.
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
.
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
.
recursiveCompare :: (Recursive (->) t f, Steppable (->) u f, Functor f, Foldable f, Ord1 f) => t -> u -> Ordering Source #
An implementation of ==
for any Recursive
instance. Note that this is
actually more general than Ord
’s compare
, as it can compare between
different fixed-point representations of the same functor.
NB: Use recursiveCompare'
if you need to use a custom comparator for
f
.
Since: 0.6.1.0
recursiveCompare' :: (Recursive (->) t f, Steppable (->) u f, Functor f, Foldable f) => (f () -> f () -> Ordering) -> t -> u -> Ordering Source #
Like recursiveCompare
, but allows you to provide a custom comparator for
f
.
Since: 0.6.1.0
recursiveEq :: (Recursive (->) t f, Steppable (->) u f, Functor f, Foldable f, Eq1 f) => t -> u -> Bool Source #
An implementation of ==
for any Recursive
instance. Note that this is
actually more general than Eq
’s ==
, as it can compare between different
fixed-point representations of the same functor.
NB: Use recursiveEq'
if you need to use a custom comparator for f
.
recursiveEq' :: (Recursive (->) t f, Steppable (->) u f, Functor f, Foldable f) => (f () -> f () -> Bool) -> t -> u -> Bool Source #
Like recursiveEq
, but allows you to provide a custom comparator for f
.
Since: 0.6.1.0
recursivePrism :: (Recursive (->) t f, Corecursive (->) t f, Traversable f) => AlgebraPrism f a -> Prism' t a Source #
recursiveShowsPrec' :: Recursive (->) t f => Algebra (->) f (Int -> ShowS) -> Int -> t -> ShowS Source #
Like recursiveShowsPrec
, but allows you to provide a custom display
function for f
.
Since: 0.6.1.0
seqIdentity :: Functor f => DistributiveLaw (->) Identity f Source #
steppableIso :: Steppable (->) t f => BialgebraIso f t Source #
steppableReadPrec :: (Steppable (->) t f, Read1 f) => ReadPrec t Source #
An implementation of readPrec
for any Steppable
instance.
NB: Use steppableReadPrec'
if you need to use a custom parsing
function for f
.
NB: This only requires Steppable
, but the inverse operation is
recursiveShowsPrec
, which requires Recursive
instead.
Since: 0.6.1.0
steppableReadPrec' :: Steppable (->) t f => (ReadPrec t -> ReadPrec [t] -> ReadPrec (f t)) -> ReadPrec t Source #
Like steppableReadPrec
, but allows you to provide a custom display
function for f
.
Since: 0.6.1.0
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.
zipAlgebraMs :: (Applicative m, Functor f) => AlgebraM (->) m f a -> AlgebraM (->) m f b -> AlgebraM (->) m f (Pair a b) Source #