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

Applicative functor transformers for free

  • 4 types
  • 14 values
  • 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
valueliftApT :: Applicative g => f a -> ApT f g a
#

A version of lift that can be used with no constraint for f.

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

4 declarations
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

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