Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Control.Applicative.Free.Fast
Description
A faster free applicative. Based on Dave Menendez's work.
Synopsis
- data ASeq f 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 :: ASeq f u -> (forall x. (x -> y) -> ASeq f x -> z) -> (v -> u -> y) -> ASeq f v -> z
- newtype Ap f 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
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 #
Interprets the sequence of effects using the semantics for
pure
and <*>
given by the Applicative instance for f
.
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 :: 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
The faster free Applicative
.
Constructors
Ap | |
retractAp :: Applicative f => Ap f a -> f a Source #
Interprets the free applicative functor over f using the semantics for
pure
and <*>
given by the Applicative instance for f.
retractApp == runAp id
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