functor-combinators-0.3.5.1: Tools for functor combinator-based program design
Copyright (c) Justin Le 2019 BSD3 justin@jle.im experimental non-portable None Haskell2010

Data.HFunctor.Chain

Description

This module provides an Interpretable data type of "linked list of tensor applications".

The type Chain t, for any Tensor t, is meant to be the same as ListBy t (the monoidal functor combinator for t), and represents "zero or more" applications of f to t.

The type Chain1 t, for any Associative t, is meant to be the same as NonEmptyBy t (the semigroupoidal functor combinator for t) and represents "one or more" applications of f to t.

The advantage of using Chain and Chain1 over ListBy or NonEmptyBy is that they provide a universal interface for pattern matching and constructing such values, which may simplify working with new such functor combinators you might encounter.

Synopsis

# Chain

data Chain t i f a Source #

A useful construction that works like a "linked list" of t f applied to itself multiple times. That is, it contains t f f, t f (t f f), t f (t f (t f f)), etc, with f occuring zero or more times. It is meant to be the same as ListBy t.

If t is Tensor, then it means we can "collapse" this linked list into some final type ListBy t (reroll), and also extract it back into a linked list (unroll).

So, a value of type Chain t i f a is one of either:

• i a
• f a
• t f f a
• t f (t f f) a
• t f (t f (t f f)) a
• .. etc.

Note that this is exactly what an ListBy t is supposed to be. Using Chain allows us to work with all ListBy ts in a uniform way, with normal pattern matching and normal constructors.

You can fully "collapse" a Chain t i f into an f with retract, if you have MonoidIn t i f; this could be considered a fundamental property of monoid-ness.

Another way of thinking of this is that Chain t i is the "free MonoidIn t i". Given any functor f, Chain t i f is a monoid in the monoidal category of endofunctors enriched by t. So, Chain Comp Identity is the "free Monad", Chain Day Identity is the "free Applicative", etc. You "lift" from f a to Chain t i f a using inject.

Note: this instance doesn't exist directly because of restrictions in typeclasses, but is implemented as

Tensor t i => MonoidIn (WrapHBF t) (WrapF i) (Chain t i f)


where pureT is Done and biretract is appendChain.

This construction is inspired by http://oleg.fi/gists/posts/2018-02-21-single-free.html

Constructors

 Done (i a) More (t f (Chain t i f) a)

#### Instances

Instances details
 HBifunctor t => HFunctor (Chain t i :: (k -> Type) -> k -> Type) Source # Instance detailsDefined in Data.HFunctor.Chain.Internal Methodshmap :: forall (f :: k0 -> Type) (g :: k0 -> Type). (f ~> g) -> Chain t i f ~> Chain t i g Source # Tensor t i => Inject (Chain t i :: (Type -> Type) -> Type -> Type) Source # Instance detailsDefined in Data.HFunctor.Chain Methodsinject :: forall (f :: k -> Type). f ~> Chain t i f Source # MonoidIn t i f => Interpret (Chain t i :: (Type -> Type) -> Type -> Type) (f :: Type -> Type) Source # We can collapse and interpret an Chain t i if we have Tensor t. Instance detailsDefined in Data.HFunctor.Chain Methodsretract :: Chain t i f ~> f Source #interpret :: forall (g :: k -> Type). (g ~> f) -> Chain t i g ~> f Source # (Tensor t i, FunctorBy t (Chain t i f)) => MonoidIn (WrapHBF t) (WrapF i) (Chain t i f) Source # Chain t i is the "free MonoidIn t i". However, we have to wrap t in WrapHBF and i in WrapF to prevent overlapping instances. Instance detailsDefined in Data.HFunctor.Chain MethodspureT :: WrapF i ~> Chain t i f Source # (Tensor t i, FunctorBy t (Chain t i f)) => SemigroupIn (WrapHBF t) (Chain t i f) Source # We have to wrap t in WrapHBF to prevent overlapping instances. Instance detailsDefined in Data.HFunctor.Chain Methodsbiretract :: WrapHBF t (Chain t i f) (Chain t i f) ~> Chain t i f Source #binterpret :: forall (g :: Type -> Type) (h :: Type -> Type). (g ~> Chain t i f) -> (h ~> Chain t i f) -> WrapHBF t g h ~> Chain t i f Source # Monad (Chain (Comp :: (Type -> Type) -> (Type -> Type) -> Type -> Type) Identity f) Source # Chain Comp Identity is the free "monoid in the monoidal category of endofunctors enriched by Comp" --- aka, the free Monad. Instance detailsDefined in Data.HFunctor.Chain Methods(>>=) :: Chain Comp Identity f a -> (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 b #return :: a -> Chain Comp Identity f a # (Functor i, Functor (t f (Chain t i f))) => Functor (Chain t i f) Source # Instance detailsDefined in Data.HFunctor.Chain.Internal Methodsfmap :: (a -> b) -> Chain t i f a -> Chain t i f b #(<$) :: a -> Chain t i f b -> Chain t i f a # Source # Chain Day Identity is the free "monoid in the monoidal category of endofunctors enriched by Day" --- aka, the free Applicative. Instance detailsDefined in Data.HFunctor.Chain Methodspure :: a -> Chain Day Identity f a #(<*>) :: Chain Day Identity f (a -> b) -> Chain Day Identity f a -> Chain Day Identity f b #liftA2 :: (a -> b -> c) -> Chain Day Identity f a -> Chain Day Identity f b -> Chain Day Identity f c #(*>) :: Chain Day Identity f a -> Chain Day Identity f b -> Chain Day Identity f b #(<*) :: Chain Day Identity f a -> Chain Day Identity f b -> Chain Day Identity f a # Applicative (Chain (Comp :: (Type -> Type) -> (Type -> Type) -> Type -> Type) Identity f) Source # Instance detailsDefined in Data.HFunctor.Chain Methodspure :: 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 # (Foldable i, Foldable (t f (Chain t i f))) => Foldable (Chain t i f) Source # Instance detailsDefined in Data.HFunctor.Chain.Internal Methodsfold :: Monoid m => Chain t i f m -> m #foldMap :: Monoid m => (a -> m) -> Chain t i f a -> m #foldMap' :: Monoid m => (a -> m) -> Chain t i f a -> m #foldr :: (a -> b -> b) -> b -> Chain t i f a -> b #foldr' :: (a -> b -> b) -> b -> Chain t i f a -> b #foldl :: (b -> a -> b) -> b -> Chain t i f a -> b #foldl' :: (b -> a -> b) -> b -> Chain t i f a -> b #foldr1 :: (a -> a -> a) -> Chain t i f a -> a #foldl1 :: (a -> a -> a) -> Chain t i f a -> a #toList :: Chain t i f a -> [a] #null :: Chain t i f a -> Bool #length :: Chain t i f a -> Int #elem :: Eq a => a -> Chain t i f a -> Bool #maximum :: Ord a => Chain t i f a -> a #minimum :: Ord a => Chain t i f a -> a #sum :: Num a => Chain t i f a -> a #product :: Num a => Chain t i f a -> a # (Traversable i, Traversable (t f (Chain t i f))) => Traversable (Chain t i f) Source # Instance detailsDefined in Data.HFunctor.Chain.Internal Methodstraverse :: Applicative f0 => (a -> f0 b) -> Chain t i f a -> f0 (Chain t i f b) #sequenceA :: Applicative f0 => Chain t i f (f0 a) -> f0 (Chain t i f a) #mapM :: Monad m => (a -> m b) -> Chain t i f a -> m (Chain t i f b) #sequence :: Monad m => Chain t i f (m a) -> m (Chain t i f a) # (Contravariant i, Contravariant (t f (Chain t i f))) => Contravariant (Chain t i f) Source # Instance detailsDefined in Data.HFunctor.Chain.Internal Methodscontramap :: (a -> b) -> Chain t i f b -> Chain t i f a #(>$) :: b -> Chain t i f b -> Chain t i f a # (Eq1 i, Eq1 (t f (Chain t i f))) => Eq1 (Chain t i f) Source # Instance detailsDefined in Data.HFunctor.Chain.Internal MethodsliftEq :: (a -> b -> Bool) -> Chain t i f a -> Chain t i f b -> Bool # (Ord1 i, Ord1 (t f (Chain t i f))) => Ord1 (Chain t i f) Source # Instance detailsDefined in Data.HFunctor.Chain.Internal MethodsliftCompare :: (a -> b -> Ordering) -> Chain t i f a -> Chain t i f b -> Ordering # (Functor i, Read1 (t f (Chain t i f)), Read1 i) => Read1 (Chain t i f) Source # Instance detailsDefined in Data.HFunctor.Chain.Internal MethodsliftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (Chain t i f a) #liftReadList :: (Int -> ReadS a) -> ReadS [a] -> ReadS [Chain t i f a] #liftReadPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec (Chain t i f a) #liftReadListPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec [Chain t i f a] # (Show1 (t f (Chain t i f)), Show1 i) => Show1 (Chain t i f) Source # Instance detailsDefined in Data.HFunctor.Chain.Internal MethodsliftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> Chain t i f a -> ShowS #liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [Chain t i f a] -> ShowS # Divisible (Chain Day (Proxy :: Type -> Type) f) Source # Chain Day Proxy is the free "monoid in the monoidal category of endofunctors enriched by contravariant Day" --- aka, the free Divisible.Since: 0.3.0.0 Instance detailsDefined in Data.HFunctor.Chain Methodsdivide :: (a -> (b, c)) -> Chain Day Proxy f b -> Chain Day Proxy f c -> Chain Day Proxy f a # (Invariant i, Invariant (t f (Chain t i f))) => Invariant (Chain t i f) Source # Instance detailsDefined in Data.HFunctor.Chain.Internal Methodsinvmap :: (a -> b) -> (b -> a) -> Chain t i f a -> Chain t i f b # Source # Instance detailsDefined in Data.HFunctor.Chain Methods(<.>) :: Chain Day Identity f (a -> b) -> Chain Day Identity f a -> Chain Day Identity f b #(.>) :: Chain Day Identity f a -> Chain Day Identity f b -> Chain Day Identity f b #(<.) :: Chain Day Identity f a -> Chain Day Identity f b -> Chain Day Identity f a #liftF2 :: (a -> b -> c) -> Chain Day Identity f a -> Chain Day Identity f b -> Chain Day Identity f c # Apply (Chain (Comp :: (Type -> Type) -> (Type -> Type) -> Type -> Type) Identity f) Source # Instance detailsDefined 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 # Functor f => Plus (Chain ((:*:) :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (Proxy :: Type -> Type) f) Source # Chain (:*:) Proxy is the free "monoid in the monoidal category of endofunctors enriched by :*:" --- aka, the free Plus. Instance detailsDefined in Data.HFunctor.Chain Methodszero :: Chain (:*:) Proxy f a # Functor f => Plus (Chain (Product :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (Proxy :: Type -> Type) f) Source # Chain (:*:) Proxy is the free "monoid in the monoidal category of endofunctors enriched by :*:" --- aka, the free Plus. Instance detailsDefined in Data.HFunctor.Chain Methods Functor f => Alt (Chain ((:*:) :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (Proxy :: Type -> Type) f) Source # Instance detailsDefined in Data.HFunctor.Chain Methods() :: Chain (:*:) Proxy f a -> Chain (:*:) Proxy f a -> Chain (:*:) Proxy f a #some :: Applicative (Chain (:*:) Proxy f) => Chain (:*:) Proxy f a -> Chain (:*:) Proxy f [a] #many :: Applicative (Chain (:*:) Proxy f) => Chain (:*:) Proxy f a -> Chain (:*:) Proxy f [a] # Functor f => Alt (Chain (Product :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (Proxy :: Type -> Type) f) Source # Instance detailsDefined in Data.HFunctor.Chain Methods() :: Chain Product Proxy f a -> Chain Product Proxy f a -> Chain Product Proxy f a #some :: Applicative (Chain Product Proxy f) => Chain Product Proxy f a -> Chain Product Proxy f [a] #many :: Applicative (Chain Product Proxy f) => Chain Product Proxy f a -> Chain Product Proxy f [a] # Bind (Chain (Comp :: (Type -> Type) -> (Type -> Type) -> Type -> Type) Identity f) Source # Instance detailsDefined in Data.HFunctor.Chain Methods(>>-) :: Chain Comp Identity f a -> (a -> Chain Comp Identity f b) -> Chain Comp Identity f b #join :: Chain Comp Identity f (Chain Comp Identity f a) -> Chain Comp Identity f a # Divise (Chain Day (Proxy :: Type -> Type) f) Source # Since: 0.3.0.0 Instance detailsDefined in Data.HFunctor.Chain Methodsdivise :: (a -> (b, c)) -> Chain Day Proxy f b -> Chain Day Proxy f c -> Chain Day Proxy f a Source # Source # Since: 0.3.0.0 Instance detailsDefined in Data.HFunctor.Chain Methodsdecide :: (a -> Either b c) -> Chain Night Not f b -> Chain Night Not f c -> Chain Night Not f a Source # Source # Chain Night Refutec is the free "monoid in the monoidal category of endofunctors enriched by Night" --- aka, the free Conclude.Since: 0.3.0.0 Instance detailsDefined in Data.HFunctor.Chain Methodsconclude :: (a -> Void) -> Chain Night Not f a Source # (Eq (i a), Eq (t f (Chain t i f) a)) => Eq (Chain t i f a) Source # Instance detailsDefined in Data.HFunctor.Chain.Internal Methods(==) :: Chain t i f a -> Chain t i f a -> Bool #(/=) :: Chain t i f a -> Chain t i f a -> Bool # (Ord (i a), Ord (t f (Chain t i f) a)) => Ord (Chain t i f a) Source # Instance detailsDefined in Data.HFunctor.Chain.Internal Methodscompare :: Chain t i f a -> Chain t i f a -> Ordering #(<) :: Chain t i f a -> Chain t i f a -> Bool #(<=) :: Chain t i f a -> Chain t i f a -> Bool #(>) :: Chain t i f a -> Chain t i f a -> Bool #(>=) :: Chain t i f a -> Chain t i f a -> Bool #max :: Chain t i f a -> Chain t i f a -> Chain t i f a #min :: Chain t i f a -> Chain t i f a -> Chain t i f a # (Read (i a), Read (t f (Chain t i f) a)) => Read (Chain t i f a) Source # Instance detailsDefined in Data.HFunctor.Chain.Internal MethodsreadsPrec :: Int -> ReadS (Chain t i f a) #readList :: ReadS [Chain t i f a] #readPrec :: ReadPrec (Chain t i f a) #readListPrec :: ReadPrec [Chain t i f a] # (Show (i a), Show (t f (Chain t i f) a)) => Show (Chain t i f a) Source # Instance detailsDefined in Data.HFunctor.Chain.Internal MethodsshowsPrec :: Int -> Chain t i f a -> ShowS #show :: Chain t i f a -> String #showList :: [Chain t i f a] -> ShowS #

Arguments

 :: forall t i f g. HBifunctor t => (i ~> g) Handle Done -> (t f g ~> g) Handle More -> Chain t i f ~> g

Recursively fold down a Chain. Provide a function on how to handle the "single f case" (nilLB), and how to handle the "combined t f g case", and this will fold the entire Chain t i) f into a single g.

This is a catamorphism.

unfoldChain :: forall t f (g :: Type -> Type) i. HBifunctor t => (g ~> (i :+: t f g)) -> g ~> Chain t i f Source #

Recursively build up a Chain. Provide a function that takes some starting seed g and returns either "done" (i) or "continue further" (t f g), and it will create a Chain t i f from a g.

This is an anamorphism.

unroll :: Tensor t i => ListBy t f ~> Chain t i f Source #

A type ListBy t is supposed to represent the successive application of ts to itself. unroll makes that successive application explicit, buy converting it to a literal Chain of applications of t to itself.

unroll = unfoldChain unconsLB


reroll :: forall t i f. Tensor t i => Chain t i f ~> ListBy t f Source #

A type ListBy t is supposed to represent the successive application of ts to itself. rerollNE takes an explicit Chain of applications of t to itself and rolls it back up into an ListBy t.

reroll = foldChain nilLB consLB


Because t cannot be inferred from the input or output, you should call this with -XTypeApplications:

reroll @Comp
:: Chain Comp Identity f a -> Free f a


unrolling :: Tensor t i => ListBy t f <~> Chain t i f Source #

A type ListBy t is supposed to represent the successive application of ts to itself. The type Chain t i f is an actual concrete ADT that contains successive applications of t to itself, and you can pattern match on each layer.

unrolling states that the two types are isormorphic. Use unroll and reroll to convert between the two.

appendChain :: forall t i f. Tensor t i => t (Chain t i f) (Chain t i f) ~> Chain t i f Source #

Chain is a monoid with respect to t: we can "combine" them in an associative way. The identity here is anything made with the Done constructor.

This is essentially biretract, but only requiring Tensor t i: it comes from the fact that Chain1 t i is the "free MonoidIn t i". pureT is Done.

Since: 0.1.1.0

splittingChain :: Chain t i f <~> (i :+: t f (Chain t i f)) Source #

For completeness, an isomorphism between Chain and its two constructors, to match splittingLB.

Since: 0.3.0.0

toChain :: Tensor t i => t f f ~> Chain t i f Source #

Convert a tensor value pairing two fs into a two-item Chain. An analogue of toListBy.

Since: 0.3.1.0

injectChain :: Tensor t i => f ~> Chain t i f Source #

Create a singleton chain.

Since: 0.3.0.0

unconsChain :: Chain t i f ~> (i :+: t f (Chain t i f)) Source #

An analogue of unconsLB: match one of the two constructors of a Chain.

Since: 0.3.0.0

# Chain1

data Chain1 t f a Source #

A useful construction that works like a "non-empty linked list" of t f applied to itself multiple times. That is, it contains t f f, t f (t f f), t f (t f (t f f)), etc, with f occuring one or more times. It is meant to be the same as NonEmptyBy t.

A Chain1 t f a is explicitly one of:

• f a
• t f f a
• t f (t f f) a
• t f (t f (t f f)) a
• .. etc

Note that this is exactly the description of NonEmptyBy t. And that's "the point": for all instances of Associative, Chain1 t is isomorphic to NonEmptyBy t (witnessed by unrollingNE). That's big picture of NonEmptyBy: it's supposed to be a type that consists of all possible self-applications of f to t.

Chain1 gives you a way to work with all NonEmptyBy t in a uniform way. Unlike for NonEmptyBy t f in general, you can always explicitly /pattern match/ on a Chain1 (with its two constructors) and do what you please with it. You can also construct Chain1 using normal constructors and functions.

You can convert in between NonEmptyBy t f and Chain1 t f with unrollNE and rerollNE. You can fully "collapse" a Chain1 t f into an f with retract, if you have SemigroupIn t f; this could be considered a fundamental property of semigroup-ness.

See Chain for a version that has an "empty" value.

Another way of thinking of this is that Chain1 t is the "free SemigroupIn t". Given any functor f, Chain1 t f is a semigroup in the semigroupoidal category of endofunctors enriched by t. So, Chain1 Comp is the "free Bind", Chain1 Day is the "free Apply", etc. You "lift" from f a to Chain1 t f a using inject.

Note: this instance doesn't exist directly because of restrictions in typeclasses, but is implemented as

Associative t => SemigroupIn (WrapHBF t) (Chain1 t f)


where biretract is appendChain1.

You can fully "collapse" a Chain t i f into an f with retract, if you have MonoidIn t i f; this could be considered a fundamental property of monoid-ness.

This construction is inspired by iteratees and machines.

Constructors

 Done1 (f a) More1 (t f (Chain1 t f) a)

#### Instances

Instances details
 HBifunctor t => HFunctor (Chain1 t :: (k -> Type) -> k -> Type) Source # Instance detailsDefined in Data.HFunctor.Chain.Internal Methodshmap :: forall (f :: k0 -> Type) (g :: k0 -> Type). (f ~> g) -> Chain1 t f ~> Chain1 t g Source # HBifunctor t => Inject (Chain1 t :: (k -> Type) -> k -> Type) Source # Instance detailsDefined in Data.HFunctor.Chain.Internal Methodsinject :: forall (f :: k0 -> Type). f ~> Chain1 t f Source # (HBifunctor t, SemigroupIn t f) => Interpret (Chain1 t :: (Type -> Type) -> Type -> Type) (f :: Type -> Type) Source # Instance detailsDefined in Data.HFunctor.Chain Methodsretract :: Chain1 t f ~> f Source #interpret :: forall (g :: k -> Type). (g ~> f) -> Chain1 t g ~> f Source # (Functor f, Functor (t f (Chain1 t f))) => Functor (Chain1 t f) Source # Instance detailsDefined in Data.HFunctor.Chain.Internal Methodsfmap :: (a -> b) -> Chain1 t f a -> Chain1 t f b #(<$) :: a -> Chain1 t f b -> Chain1 t f a # (Foldable f, Foldable (t f (Chain1 t f))) => Foldable (Chain1 t f) Source # Instance detailsDefined in Data.HFunctor.Chain.Internal Methodsfold :: Monoid m => Chain1 t f m -> m #foldMap :: Monoid m => (a -> m) -> Chain1 t f a -> m #foldMap' :: Monoid m => (a -> m) -> Chain1 t f a -> m #foldr :: (a -> b -> b) -> b -> Chain1 t f a -> b #foldr' :: (a -> b -> b) -> b -> Chain1 t f a -> b #foldl :: (b -> a -> b) -> b -> Chain1 t f a -> b #foldl' :: (b -> a -> b) -> b -> Chain1 t f a -> b #foldr1 :: (a -> a -> a) -> Chain1 t f a -> a #foldl1 :: (a -> a -> a) -> Chain1 t f a -> a #toList :: Chain1 t f a -> [a] #null :: Chain1 t f a -> Bool #length :: Chain1 t f a -> Int #elem :: Eq a => a -> Chain1 t f a -> Bool #maximum :: Ord a => Chain1 t f a -> a #minimum :: Ord a => Chain1 t f a -> a #sum :: Num a => Chain1 t f a -> a #product :: Num a => Chain1 t f a -> a # (Traversable f, Traversable (t f (Chain1 t f))) => Traversable (Chain1 t f) Source # Instance detailsDefined in Data.HFunctor.Chain.Internal Methodstraverse :: Applicative f0 => (a -> f0 b) -> Chain1 t f a -> f0 (Chain1 t f b) #sequenceA :: Applicative f0 => Chain1 t f (f0 a) -> f0 (Chain1 t f a) #mapM :: Monad m => (a -> m b) -> Chain1 t f a -> m (Chain1 t f b) #sequence :: Monad m => Chain1 t f (m a) -> m (Chain1 t f a) # (Contravariant f, Contravariant (t f (Chain1 t f))) => Contravariant (Chain1 t f) Source # Since: 0.3.0.0 Instance detailsDefined in Data.HFunctor.Chain.Internal Methodscontramap :: (a -> b) -> Chain1 t f b -> Chain1 t f a #(>$) :: b -> Chain1 t f b -> Chain1 t f a # (Eq1 f, Eq1 (t f (Chain1 t f))) => Eq1 (Chain1 t f) Source # Instance detailsDefined in Data.HFunctor.Chain.Internal MethodsliftEq :: (a -> b -> Bool) -> Chain1 t f a -> Chain1 t f b -> Bool # (Ord1 f, Ord1 (t f (Chain1 t f))) => Ord1 (Chain1 t f) Source # Instance detailsDefined in Data.HFunctor.Chain.Internal MethodsliftCompare :: (a -> b -> Ordering) -> Chain1 t f a -> Chain1 t f b -> Ordering # (Functor f, Read1 (t f (Chain1 t f)), Read1 f) => Read1 (Chain1 t f) Source # Instance detailsDefined in Data.HFunctor.Chain.Internal MethodsliftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (Chain1 t f a) #liftReadList :: (Int -> ReadS a) -> ReadS [a] -> ReadS [Chain1 t f a] #liftReadPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec (Chain1 t f a) #liftReadListPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec [Chain1 t f a] # (Show1 (t f (Chain1 t f)), Show1 f) => Show1 (Chain1 t f) Source # Instance detailsDefined in Data.HFunctor.Chain.Internal MethodsliftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> Chain1 t f a -> ShowS #liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [Chain1 t f a] -> ShowS # (Invariant f, Invariant (t f (Chain1 t f))) => Invariant (Chain1 t f) Source # Since: 0.3.0.0 Instance detailsDefined in Data.HFunctor.Chain.Internal Methodsinvmap :: (a -> b) -> (b -> a) -> Chain1 t f a -> Chain1 t f b # Functor f => Apply (Chain1 Day f) Source # Chain1 Day is the free "semigroup in the semigroupoidal category of endofunctors enriched by Day" --- aka, the free Apply. Instance detailsDefined in Data.HFunctor.Chain Methods(<.>) :: Chain1 Day f (a -> b) -> Chain1 Day f a -> Chain1 Day f b #(.>) :: Chain1 Day f a -> Chain1 Day f b -> Chain1 Day f b #(<.) :: Chain1 Day f a -> Chain1 Day f b -> Chain1 Day f a #liftF2 :: (a -> b -> c) -> Chain1 Day f a -> Chain1 Day f b -> Chain1 Day f c # Functor f => Apply (Chain1 (Comp :: (Type -> Type) -> (Type -> Type) -> Type -> Type) f) Source # Instance detailsDefined in Data.HFunctor.Chain Methods(<.>) :: Chain1 Comp f (a -> b) -> Chain1 Comp f a -> Chain1 Comp f b #(.>) :: Chain1 Comp f a -> Chain1 Comp f b -> Chain1 Comp f b #(<.) :: Chain1 Comp f a -> Chain1 Comp f b -> Chain1 Comp f a #liftF2 :: (a -> b -> c) -> Chain1 Comp f a -> Chain1 Comp f b -> Chain1 Comp f c # Functor f => Alt (Chain1 ((:*:) :: (Type -> Type) -> (Type -> Type) -> Type -> Type) f) Source # Chain1 (:*:) is the free "semigroup in the semigroupoidal category of endofunctors enriched by :*:" --- aka, the free Alt. Instance detailsDefined in Data.HFunctor.Chain Methods() :: Chain1 (:*:) f a -> Chain1 (:*:) f a -> Chain1 (:*:) f a #some :: Applicative (Chain1 (:*:) f) => Chain1 (:*:) f a -> Chain1 (:*:) f [a] #many :: Applicative (Chain1 (:*:) f) => Chain1 (:*:) f a -> Chain1 (:*:) f [a] # Functor f => Alt (Chain1 (Product :: (Type -> Type) -> (Type -> Type) -> Type -> Type) f) Source # Chain1 Product is the free "semigroup in the semigroupoidal category of endofunctors enriched by Product" --- aka, the free Alt. Instance detailsDefined in Data.HFunctor.Chain Methods() :: Chain1 Product f a -> Chain1 Product f a -> Chain1 Product f a #some :: Applicative (Chain1 Product f) => Chain1 Product f a -> Chain1 Product f [a] #many :: Applicative (Chain1 Product f) => Chain1 Product f a -> Chain1 Product f [a] # Functor f => Bind (Chain1 (Comp :: (Type -> Type) -> (Type -> Type) -> Type -> Type) f) Source # Chain1 Comp is the free "semigroup in the semigroupoidal category of endofunctors enriched by Comp" --- aka, the free Bind. Instance detailsDefined in Data.HFunctor.Chain Methods(>>-) :: Chain1 Comp f a -> (a -> Chain1 Comp f b) -> Chain1 Comp f b #join :: Chain1 Comp f (Chain1 Comp f a) -> Chain1 Comp f a # Contravariant f => Divise (Chain1 Day f) Source # Chain1 Day is the free "semigroup in the semigroupoidal category of endofunctors enriched by Day" --- aka, the free Divise.Since: 0.3.0.0 Instance detailsDefined in Data.HFunctor.Chain Methodsdivise :: (a -> (b, c)) -> Chain1 Day f b -> Chain1 Day f c -> Chain1 Day f a Source # Source # Chain1 Night is the free "semigroup in the semigroupoidal category of endofunctors enriched by Night" --- aka, the free Decide.Since: 0.3.0.0 Instance detailsDefined in Data.HFunctor.Chain Methodsdecide :: (a -> Either b c) -> Chain1 Night f b -> Chain1 Night f c -> Chain1 Night f a Source # (Eq (f a), Eq (t f (Chain1 t f) a)) => Eq (Chain1 t f a) Source # Instance detailsDefined in Data.HFunctor.Chain.Internal Methods(==) :: Chain1 t f a -> Chain1 t f a -> Bool #(/=) :: Chain1 t f a -> Chain1 t f a -> Bool # (Ord (f a), Ord (t f (Chain1 t f) a)) => Ord (Chain1 t f a) Source # Instance detailsDefined in Data.HFunctor.Chain.Internal Methodscompare :: Chain1 t f a -> Chain1 t f a -> Ordering #(<) :: Chain1 t f a -> Chain1 t f a -> Bool #(<=) :: Chain1 t f a -> Chain1 t f a -> Bool #(>) :: Chain1 t f a -> Chain1 t f a -> Bool #(>=) :: Chain1 t f a -> Chain1 t f a -> Bool #max :: Chain1 t f a -> Chain1 t f a -> Chain1 t f a #min :: Chain1 t f a -> Chain1 t f a -> Chain1 t f a # (Read (f a), Read (t f (Chain1 t f) a)) => Read (Chain1 t f a) Source # Instance detailsDefined in Data.HFunctor.Chain.Internal MethodsreadsPrec :: Int -> ReadS (Chain1 t f a) #readList :: ReadS [Chain1 t f a] #readPrec :: ReadPrec (Chain1 t f a) #readListPrec :: ReadPrec [Chain1 t f a] # (Show (f a), Show (t f (Chain1 t f) a)) => Show (Chain1 t f a) Source # Instance detailsDefined in Data.HFunctor.Chain.Internal MethodsshowsPrec :: Int -> Chain1 t f a -> ShowS #show :: Chain1 t f a -> String #showList :: [Chain1 t f a] -> ShowS # Generic (Chain1 t f a) Source # Instance detailsDefined in Data.HFunctor.Chain.Internal Associated Typestype Rep (Chain1 t f a) :: Type -> Type # Methodsfrom :: Chain1 t f a -> Rep (Chain1 t f a) x #to :: Rep (Chain1 t f a) x -> Chain1 t f a # (Associative t, FunctorBy t f, FunctorBy t (Chain1 t f)) => SemigroupIn (WrapHBF t) (Chain1 t f) Source # Chain1 t is the "free SemigroupIn t". However, we have to wrap t in WrapHBF to prevent overlapping instances. Instance detailsDefined in Data.HFunctor.Chain Methodsbiretract :: WrapHBF t (Chain1 t f) (Chain1 t f) ~> Chain1 t f Source #binterpret :: forall (g :: Type -> Type) (h :: Type -> Type). (g ~> Chain1 t f) -> (h ~> Chain1 t f) -> WrapHBF t g h ~> Chain1 t f Source # type Rep (Chain1 t f a) Source # Instance detailsDefined in Data.HFunctor.Chain.Internal type Rep (Chain1 t f a) = D1 ('MetaData "Chain1" "Data.HFunctor.Chain.Internal" "functor-combinators-0.3.5.1-inplace" 'False) (C1 ('MetaCons "Done1" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (f a))) :+: C1 ('MetaCons "More1" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (t f (Chain1 t f) a))))

Arguments

 :: forall t f g. HBifunctor t => (f ~> g) handle Done1 -> (t f g ~> g) handle More1 -> Chain1 t f ~> g

Recursively fold down a Chain1. Provide a function on how to handle the "single f case" (inject), and how to handle the "combined t f g case", and this will fold the entire Chain1 t f into a single g.

This is a catamorphism.

unfoldChain1 :: forall t f (g :: Type -> Type). HBifunctor t => (g ~> (f :+: t f g)) -> g ~> Chain1 t f Source #

Recursively build up a Chain1. Provide a function that takes some starting seed g and returns either "done" (f) or "continue further" (t f g), and it will create a Chain1 t f from a g.

This is an anamorphism.

unrollingNE :: forall t f. (Associative t, FunctorBy t f) => NonEmptyBy t f <~> Chain1 t f Source #

A type NonEmptyBy t is supposed to represent the successive application of ts to itself. The type Chain1 t f is an actual concrete ADT that contains successive applications of t to itself, and you can pattern match on each layer.

unrollingNE states that the two types are isormorphic. Use unrollNE and rerollNE to convert between the two.

unrollNE :: (Associative t, FunctorBy t f) => NonEmptyBy t f ~> Chain1 t f Source #

A type NonEmptyBy t is supposed to represent the successive application of ts to itself. unrollNE makes that successive application explicit, buy converting it to a literal Chain1 of applications of t to itself.

unrollNE = unfoldChain1 matchNE


rerollNE :: Associative t => Chain1 t f ~> NonEmptyBy t f Source #

A type NonEmptyBy t is supposed to represent the successive application of ts to itself. rerollNE takes an explicit Chain1 of applications of t to itself and rolls it back up into an NonEmptyBy t.

rerollNE = foldChain1 inject consNE


appendChain1 :: forall t f. (Associative t, FunctorBy t f) => t (Chain1 t f) (Chain1 t f) ~> Chain1 t f Source #

Chain1 is a semigroup with respect to t: we can "combine" them in an associative way.

This is essentially biretract, but only requiring Associative t: it comes from the fact that Chain1 t is the "free SemigroupIn t".

Since: 0.1.1.0

fromChain1 :: Tensor t i => Chain1 t f ~> Chain t i f Source #

A Chain1 is "one or more linked fs", and a Chain is "zero or more linked fs". So, we can convert from a Chain1 to a Chain that always has at least one f.

The result of this function always is made with More at the top level.

matchChain1 :: Chain1 t f ~> (f :+: t f (Chain1 t f)) Source #

For completeness, an isomorphism between Chain1 and its two constructors, to match matchNE.

Since: 0.3.0.0

toChain1 :: HBifunctor t => t f f ~> Chain1 t f Source #

Convert a tensor value pairing two fs into a two-item Chain1. An analogue of toNonEmptyBy.

Since: 0.3.1.0

injectChain1 :: f ~> Chain1 t f Source #

Create a singleton Chain1.

Since: 0.3.0.0

## Matchable

The following conversions between Chain and Chain1 are only possible if t is Matchable

splittingChain1 :: forall t i f. (Matchable t i, FunctorBy t f) => Chain1 t f <~> t f (Chain t i f) Source #

A Chain1 t f is like a non-empty linked list of fs, and a Chain t i f is a possibly-empty linked list of fs. This witnesses the fact that the former is isomorphic to f consed to the latter.

splitChain1 :: forall t i f. Tensor t i => Chain1 t f ~> t f (Chain t i f) Source #

The "forward" function representing splittingChain1. Provided here as a separate function because it does not require Functor f.

matchingChain :: forall t i f. (Tensor t i, Matchable t i, FunctorBy t f) => Chain t i f <~> (i :+: Chain1 t f) Source #

A Chain t i f is a linked list of fs, and a Chain1 t f is a non-empty linked list of fs. This witnesses the fact that a Chain t i f is either empty (i) or non-empty (Chain1 t f).

unmatchChain :: forall t i f. Tensor t i => (i :+: Chain1 t f) ~> Chain t i f Source #

The "reverse" function representing matchingChain. Provided here as a separate function because it does not require Functor f.

# Orphan instances

 (HBifunctor t, SemigroupIn t f) => Interpret (Chain1 t :: (Type -> Type) -> Type -> Type) (f :: Type -> Type) Source # Instance details Methodsretract :: Chain1 t f ~> f Source #interpret :: forall (g :: k -> Type). (g ~> f) -> Chain1 t g ~> f Source # Tensor t i => Inject (Chain t i :: (Type -> Type) -> Type -> Type) Source # Instance details Methodsinject :: forall (f :: k -> Type). f ~> Chain t i f Source # MonoidIn t i f => Interpret (Chain t i :: (Type -> Type) -> Type -> Type) (f :: Type -> Type) Source # We can collapse and interpret an Chain t i if we have Tensor t. Instance details Methodsretract :: Chain t i f ~> f Source #interpret :: forall (g :: k -> Type). (g ~> f) -> Chain t i g ~> f Source # Functor f => Apply (Chain1 Day f) Source # Chain1 Day is the free "semigroup in the semigroupoidal category of endofunctors enriched by Day" --- aka, the free Apply. Instance details Methods(<.>) :: Chain1 Day f (a -> b) -> Chain1 Day f a -> Chain1 Day f b #(.>) :: Chain1 Day f a -> Chain1 Day f b -> Chain1 Day f b #(<.) :: Chain1 Day f a -> Chain1 Day f b -> Chain1 Day f a #liftF2 :: (a -> b -> c) -> Chain1 Day f a -> Chain1 Day f b -> Chain1 Day f c # Functor f => Apply (Chain1 (Comp :: (Type -> Type) -> (Type -> Type) -> Type -> Type) f) Source # Instance details Methods(<.>) :: Chain1 Comp f (a -> b) -> Chain1 Comp f a -> Chain1 Comp f b #(.>) :: Chain1 Comp f a -> Chain1 Comp f b -> Chain1 Comp f b #(<.) :: Chain1 Comp f a -> Chain1 Comp f b -> Chain1 Comp f a #liftF2 :: (a -> b -> c) -> Chain1 Comp f a -> Chain1 Comp f b -> Chain1 Comp f c # Functor f => Alt (Chain1 ((:*:) :: (Type -> Type) -> (Type -> Type) -> Type -> Type) f) Source # Chain1 (:*:) is the free "semigroup in the semigroupoidal category of endofunctors enriched by :*:" --- aka, the free Alt. Instance details Methods() :: Chain1 (:*:) f a -> Chain1 (:*:) f a -> Chain1 (:*:) f a #some :: Applicative (Chain1 (:*:) f) => Chain1 (:*:) f a -> Chain1 (:*:) f [a] #many :: Applicative (Chain1 (:*:) f) => Chain1 (:*:) f a -> Chain1 (:*:) f [a] # Functor f => Alt (Chain1 (Product :: (Type -> Type) -> (Type -> Type) -> Type -> Type) f) Source # Chain1 Product is the free "semigroup in the semigroupoidal category of endofunctors enriched by Product" --- aka, the free Alt. Instance details Methods() :: Chain1 Product f a -> Chain1 Product f a -> Chain1 Product f a #some :: Applicative (Chain1 Product f) => Chain1 Product f a -> Chain1 Product f [a] #many :: Applicative (Chain1 Product f) => Chain1 Product f a -> Chain1 Product f [a] # Functor f => Bind (Chain1 (Comp :: (Type -> Type) -> (Type -> Type) -> Type -> Type) f) Source # Chain1 Comp is the free "semigroup in the semigroupoidal category of endofunctors enriched by Comp" --- aka, the free Bind. Instance details Methods(>>-) :: Chain1 Comp f a -> (a -> Chain1 Comp f b) -> Chain1 Comp f b #join :: Chain1 Comp f (Chain1 Comp f a) -> Chain1 Comp f a # Contravariant f => Divise (Chain1 Day f) Source # Chain1 Day is the free "semigroup in the semigroupoidal category of endofunctors enriched by Day" --- aka, the free Divise.Since: 0.3.0.0 Instance details Methodsdivise :: (a -> (b, c)) -> Chain1 Day f b -> Chain1 Day f c -> Chain1 Day f a Source # Source # Chain1 Night is the free "semigroup in the semigroupoidal category of endofunctors enriched by Night" --- aka, the free Decide.Since: 0.3.0.0 Instance details Methodsdecide :: (a -> Either b c) -> Chain1 Night f b -> Chain1 Night f c -> Chain1 Night f a Source # (Tensor t i, FunctorBy t (Chain t i f)) => MonoidIn (WrapHBF t) (WrapF i) (Chain t i f) Source # Chain t i is the "free MonoidIn t i". However, we have to wrap t in WrapHBF and i in WrapF to prevent overlapping instances. Instance details MethodspureT :: WrapF i ~> Chain t i f Source # (Associative t, FunctorBy t f, FunctorBy t (Chain1 t f)) => SemigroupIn (WrapHBF t) (Chain1 t f) Source # Chain1 t is the "free SemigroupIn t". However, we have to wrap t in WrapHBF to prevent overlapping instances. Instance details Methodsbiretract :: WrapHBF t (Chain1 t f) (Chain1 t f) ~> Chain1 t f Source #binterpret :: forall (g :: Type -> Type) (h :: Type -> Type). (g ~> Chain1 t f) -> (h ~> Chain1 t f) -> WrapHBF t g h ~> Chain1 t f Source # (Tensor t i, FunctorBy t (Chain t i f)) => SemigroupIn (WrapHBF t) (Chain t i f) Source # We have to wrap t in WrapHBF to prevent overlapping instances. Instance details Methodsbiretract :: WrapHBF t (Chain t i f) (Chain t i f) ~> Chain t i f Source #binterpret :: forall (g :: Type -> Type) (h :: Type -> Type). (g ~> Chain t i f) -> (h ~> Chain t i f) -> WrapHBF t g h ~> Chain t i f Source # Monad (Chain (Comp :: (Type -> Type) -> (Type -> Type) -> Type -> Type) Identity f) Source # Chain Comp Identity is the free "monoid in the monoidal category of endofunctors enriched by Comp" --- aka, the free Monad. Instance details Methods(>>=) :: Chain Comp Identity f a -> (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 b #return :: a -> Chain Comp Identity f a # Source # Chain Day Identity is the free "monoid in the monoidal category of endofunctors enriched by Day" --- aka, the free Applicative. Instance details Methodspure :: a -> Chain Day Identity f a #(<*>) :: Chain Day Identity f (a -> b) -> Chain Day Identity f a -> Chain Day Identity f b #liftA2 :: (a -> b -> c) -> Chain Day Identity f a -> Chain Day Identity f b -> Chain Day Identity f c #(*>) :: Chain Day Identity f a -> Chain Day Identity f b -> Chain Day Identity f b #(<*) :: Chain Day Identity f a -> Chain Day Identity f b -> Chain Day Identity f a # Applicative (Chain (Comp :: (Type -> Type) -> (Type -> Type) -> Type -> Type) Identity f) Source # Instance details Methodspure :: 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 # Divisible (Chain Day (Proxy :: Type -> Type) f) Source # Chain Day Proxy is the free "monoid in the monoidal category of endofunctors enriched by contravariant Day" --- aka, the free Divisible.Since: 0.3.0.0 Instance details Methodsdivide :: (a -> (b, c)) -> Chain Day Proxy f b -> Chain Day Proxy f c -> Chain Day Proxy f a # Source # Instance details Methods(<.>) :: Chain Day Identity f (a -> b) -> Chain Day Identity f a -> Chain Day Identity f b #(.>) :: Chain Day Identity f a -> Chain Day Identity f b -> Chain Day Identity f b #(<.) :: Chain Day Identity f a -> Chain Day Identity f b -> Chain Day Identity f a #liftF2 :: (a -> b -> c) -> Chain Day Identity f a -> Chain Day Identity f b -> Chain Day Identity f c # Apply (Chain (Comp :: (Type -> Type) -> (Type -> Type) -> Type -> Type) Identity f) Source # Instance details 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 # Functor f => Plus (Chain ((:*:) :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (Proxy :: Type -> Type) f) Source # Chain (:*:) Proxy is the free "monoid in the monoidal category of endofunctors enriched by :*:" --- aka, the free Plus. Instance details Methodszero :: Chain (:*:) Proxy f a # Functor f => Plus (Chain (Product :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (Proxy :: Type -> Type) f) Source # Chain (:*:) Proxy is the free "monoid in the monoidal category of endofunctors enriched by :*:" --- aka, the free Plus. Instance details Methods Functor f => Alt (Chain ((:*:) :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (Proxy :: Type -> Type) f) Source # Instance details Methods() :: Chain (:*:) Proxy f a -> Chain (:*:) Proxy f a -> Chain (:*:) Proxy f a #some :: Applicative (Chain (:*:) Proxy f) => Chain (:*:) Proxy f a -> Chain (:*:) Proxy f [a] #many :: Applicative (Chain (:*:) Proxy f) => Chain (:*:) Proxy f a -> Chain (:*:) Proxy f [a] # Functor f => Alt (Chain (Product :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (Proxy :: Type -> Type) f) Source # Instance details Methods() :: Chain Product Proxy f a -> Chain Product Proxy f a -> Chain Product Proxy f a #some :: Applicative (Chain Product Proxy f) => Chain Product Proxy f a -> Chain Product Proxy f [a] #many :: Applicative (Chain Product Proxy f) => Chain Product Proxy f a -> Chain Product Proxy f [a] # Bind (Chain (Comp :: (Type -> Type) -> (Type -> Type) -> Type -> Type) Identity f) Source # Instance details Methods(>>-) :: Chain Comp Identity f a -> (a -> Chain Comp Identity f b) -> Chain Comp Identity f b #join :: Chain Comp Identity f (Chain Comp Identity f a) -> Chain Comp Identity f a # Divise (Chain Day (Proxy :: Type -> Type) f) Source # Since: 0.3.0.0 Instance details Methodsdivise :: (a -> (b, c)) -> Chain Day Proxy f b -> Chain Day Proxy f c -> Chain Day Proxy f a Source # Source # Since: 0.3.0.0 Instance details Methodsdecide :: (a -> Either b c) -> Chain Night Not f b -> Chain Night Not f c -> Chain Night Not f a Source # Source # Chain Night Refutec is the free "monoid in the monoidal category of endofunctors enriched by Night" --- aka, the free Conclude.Since: 0.3.0.0 Instance details Methodsconclude :: (a -> Void) -> Chain Night Not f a Source #