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

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 77a8662 · 2026-10-31

Modulefree-5.2Haskell2010

Control.Applicative.Trans.Free

Applicative functor transformers for free

Contents
  1. Free Applicative
  2. Free Alternative
Synopsis
  • Packagefree-5.2
  • Exports18
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceFree.hs

Compared to the free monad transformers, 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.

See Free Applicative Functors, by Paolo Capriotti and Ambrus Kaposi, for some applications.

newtypenewtype ApT (f :: Type -> Type) (g :: Type -> Type) a

The free Applicative transformer for a Functor f over Applicative g.

Constructors

Instances4Functor, Applicative, Alternative, Apply
valuerunApT
  1. :: (Applicative h, Functor g)
  2. => forall a. f a -> h a
  3. -> forall a. g (h a) -> h a
  4. -> ApT f g b
  5. -> h b

Given natural transformations f ~> h and g . h ~> h this gives a natural transformation ApT f g ~> h.

valuerunApF
  1. :: (Applicative h, Functor g)
  2. => forall a. f a -> h a
  3. -> forall a. g (h a) -> h a
  4. -> ApF f g b
  5. -> h b

Given natural transformations f ~> h and g . h ~> h this gives a natural transformation ApF f g ~> h.

valuehoistApT :: Functor g => (forall a. f a -> f' a) -> ApT f g b -> ApT f' g b

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

valuehoistApF :: Functor g => (forall a. f a -> f' a) -> ApF f g b -> ApF f' g b

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

valuetransApT :: Functor g => (forall a. g a -> g' a) -> ApT f g b -> ApT f g' b

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

valuetransApF :: Functor g => (forall a. g a -> g' a) -> ApF f g b -> ApF f g' b

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

Free Applicative

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 x. f x -> m) -> Ap f a -> m

Perform a monoidal analysis over free applicative value.

Example:

count :: Ap f a -> Int
count = getSum . runAp_ (\_ -> Sum 1)
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

Free Alternative

valuerunAlt
  1. :: (Alternative g, Foldable t)
  2. => forall x. f x -> g x
  3. -> ApT f t a
  4. -> g a

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