HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulefree-5.2Haskell2010

Control.Applicative.Free.Final

Final encoding of free Applicative functors.

  • 1 type
  • 5 values
  • Packagefree-5.2
  • Exports6
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceFinal.hs

Compared to the free monad, they are less expressive. However, they are also more flexible to inspect and interpret, as the number of ways in which the values can be nested is more limited.

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)
valueliftAp :: f a -> Ap f a
#

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

valuehoistAp :: (forall a. f a -> g a) -> Ap f b -> Ap g b
#

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

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

Examples

0 declarations