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.
Modulefree-5.2Haskell2010
Control.Applicative.Free.Fast
A faster free applicative. Based on Dave Menendez's work.
Synopsis
- data ASeq
- value reduceASeq
- value hoistASeq
- value traverseASeq
- value rebaseASeq
- newtype Ap
- value liftAp
- value retractAp
- value runAp
- value runAp_
- value hoistAp
- Packagefree-5.2
- Exports11
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourceFast.hs
The Sequence of Effects
Given a natural transformation from f to g this gives a natural transformation from ASeq f to ASeq g.
Traverse a sequence with resepect to its interpretation type f.
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.
A version of lift that can be used with just a Functor for f.
Given a natural transformation from f to g, this gives a canonical monoidal natural transformation from Ap f to g.
runAp t == retractApp . hoistApp tPerform a monoidal analysis over free applicative value.
Example:
count :: Ap f a -> Int
count = getSum . runAp_ (\_ -> Sum 1)
Given a natural transformation from f to g this gives a monoidal natural transformation from Ap f to Ap g.