Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
A faster free applicative. Based on Dave Menendez's work.
Synopsis
- data ASeq (f :: Type -> Type) a where
- reduceASeq :: Applicative f => ASeq f u -> f u
- hoistASeq :: (forall x. f x -> g x) -> ASeq f a -> ASeq g a
- traverseASeq :: Applicative h => (forall x. f x -> h (g x)) -> ASeq f a -> h (ASeq g a)
- rebaseASeq :: forall (f :: Type -> Type) u y z v. ASeq f u -> (forall x. (x -> y) -> ASeq f x -> z) -> (v -> u -> y) -> ASeq f v -> z
- newtype Ap (f :: Type -> Type) a = Ap {}
- liftAp :: f a -> Ap f a
- retractAp :: Applicative f => Ap f a -> f a
- runAp :: Applicative g => (forall x. f x -> g x) -> Ap f a -> g a
- runAp_ :: Monoid m => (forall a. f a -> m) -> Ap f b -> m
- hoistAp :: (forall x. f x -> g x) -> Ap f a -> Ap g a
The Sequence of Effects
data ASeq (f :: Type -> Type) a where Source #
The free applicative is composed of a sequence of effects,
and a pure function to apply that sequence to.
The fast free applicative separates these from each other,
so that the sequence may be built up independently,
and so that fmap
can run in constant time by having immediate access to the pure function.
reduceASeq :: Applicative f => ASeq f u -> f u Source #
hoistASeq :: (forall x. f x -> g x) -> ASeq f a -> ASeq g a Source #
Given a natural transformation from f
to g
this gives a natural transformation from ASeq f
to ASeq g
.
traverseASeq :: Applicative h => (forall x. f x -> h (g x)) -> ASeq f a -> h (ASeq g a) Source #
Traverse a sequence with resepect to its interpretation type f
.
rebaseASeq :: forall (f :: Type -> Type) u y z v. ASeq f u -> (forall x. (x -> y) -> ASeq f x -> z) -> (v -> u -> y) -> ASeq f v -> z Source #
It may not be obvious, but this essentially acts like ++, traversing the first sequence and creating a new one by appending the second sequence. The difference is that this also has to modify the return functions and that the return type depends on the input types.
See the source of hoistAp
as an example usage.
The Faster Free Applicative
newtype Ap (f :: Type -> Type) a Source #
The faster free Applicative
.
retractAp :: Applicative f => Ap f a -> f a Source #
runAp :: Applicative g => (forall x. f x -> g x) -> Ap f a -> g a Source #
Given a natural transformation from f
to g
, this gives a canonical monoidal natural transformation from
to Ap
fg
.
runAp t == retractApp . hoistApp t