HORIZON HASKELLDocslts/ghc-10.0.x8fef28d2026-11-02Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8fef28d · 2026-11-02

Modulefree-5.2Haskell2010

Control.Applicative.Free.Fast

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

Contents
  1. The Sequence of Effects
  2. The Faster Free Applicative
Synopsis
  • Packagefree-5.2
  • Exports11
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceFast.hs

The Sequence of Effects

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

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

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
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.