HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulefree-5.2Haskell2010

Control.Applicative.Free.Fast

A faster free applicative. Based on Dave Menendez's work.

  • 2 types
  • 9 values
  • Packagefree-5.2
  • Exports11
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceFast.hs

The Sequence of Effects

5 declarations
datadata ASeq (f :: Type -> Type) a where
#

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.

Constructors

valuereduceASeq :: Applicative f => ASeq f u -> f u
#

Interprets the sequence of effects using the semantics for pure and <*> given by the Applicative instance for f.

valuehoistASeq :: (forall x. f x -> g x) -> ASeq f a -> ASeq g a
#

Given a natural transformation from f to g this gives a natural transformation from ASeq f to ASeq g.

valuerebaseASeq
  1. :: ASeq f u
  2. -> forall x. (x -> y) -> ASeq f x -> z
  3. -> v -> u -> y
  4. -> ASeq f v
  5. -> z
#

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

6 declarations
newtypenewtype Ap (f :: Type -> Type) a
#

The faster free Applicative.

Constructors

  • Ap
    • unAp :: forall u y z. (forall x. (x -> y) -> ASeq f x -> z) -> (u -> a -> y) -> ASeq f u -> z
Instances3Functor, Applicative, Apply
  • Functor (Ap f)Defined in free-5.2 · Control.Applicative.Free.Fast
  • Applicative (Ap f)Defined in free-5.2 · Control.Applicative.Free.Fast
  • Apply (Ap f)Defined in free-5.2 · Control.Applicative.Free.Fast
valueliftAp :: f a -> Ap f a
#

A version of lift that can be used with just a Functor for f.

valueretractAp :: Applicative f => Ap f a -> f a
#

Interprets the free applicative functor over f using the semantics for pure and <*> given by the Applicative instance for f.

Property
retractApp == runAp id
valuerunAp :: Applicative g => (forall x. f x -> g x) -> Ap f a -> g a
#

Given a natural transformation from f to g, this gives a canonical monoidal natural transformation from Ap f to g.

Property
runAp t == retractApp . hoistApp t
valuerunAp_ :: Monoid m => (forall a. f a -> m) -> Ap f b -> m
#

Perform a monoidal analysis over free applicative value.

Example:

count :: Ap f a -> Int
count = getSum . runAp_ (\_ -> Sum 1)
valuehoistAp :: (forall x. f x -> g x) -> Ap f a -> Ap g a
#

Given a natural transformation from f to g this gives a monoidal natural transformation from Ap f to Ap g.