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

Applicative functors for free

  • 1 type
  • 6 values
  • Packagefree-5.2
  • Exports7
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceFree.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.

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

datadata Ap (f :: Type -> Type) a where
#

The free Applicative for a Functor f.

Constructors

Instances10Functor, Applicative, Foldable, Foldable1, Eq1, Ord1, …
  • Functor (Ap f)Defined in free-5.2 · Control.Applicative.Free
  • Applicative (Ap f)Defined in free-5.2 · Control.Applicative.Free
  • Foldable f => Foldable (Ap f)Defined in free-5.2 · Control.Applicative.Free
    foldMap f == foldMap f . runAp toList
  • Foldable1 f => Foldable1 (Ap f)Defined in free-5.2 · Control.Applicative.Free
    foldMap f == foldMap f . runAp toNonEmpty
  • Eq1 f => Eq1 (Ap f)Defined in free-5.2 · Control.Applicative.Free
  • Ord1 f => Ord1 (Ap f)Defined in free-5.2 · Control.Applicative.Free
  • Comonad f => Comonad (Ap f)Defined in free-5.2 · Control.Applicative.Free
  • Apply (Ap f)Defined in free-5.2 · Control.Applicative.Free
  • (Eq1 f, Eq a) => Eq (Ap f a)Defined in free-5.2 · Control.Applicative.Free
  • (Ord1 f, Ord a) => Ord (Ap f a)Defined in free-5.2 · Control.Applicative.Free
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