HORIZON HASKELLDocslts/ghc-10.0.x2b276322026-10-31Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 2b27632 · 2026-10-31

Modulefree-5.2Haskell2010

Control.Applicative.Free.Final

Final encoding of free Applicative functors.

Contents
  1. Examples
Synopsis
  • 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)
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