Copyright | (C) 2012-2013 Edward Kmett |
---|---|
License | BSD-style (see the file LICENSE) |
Maintainer | Edward Kmett <ekmett@gmail.com> |
Stability | provisional |
Portability | GADTs, Rank2Types |
Safe Haskell | Safe |
Language | Haskell2010 |
Applicative
functors for free
Synopsis
- data Ap f a where
- runAp :: Applicative g => (forall x. f x -> g x) -> Ap f a -> g a
- runAp_ :: Monoid m => (forall a. f a -> m) -> Ap f b -> m
- liftAp :: f a -> Ap f a
- iterAp :: Functor g => (g a -> a) -> Ap g a -> a
- hoistAp :: (forall a. f a -> g a) -> Ap f b -> Ap g b
- retractAp :: Applicative f => Ap f a -> f a
Documentation
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.
The free Applicative
for a Functor
f
.
runAp :: 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
to Ap
fg
.
runAp t == retractApp . hoistApp t
runAp_ :: 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)
iterAp :: Functor g => (g a -> a) -> Ap g a -> a #
Tear down a free Applicative
using iteration.
hoistAp :: (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
.
retractAp :: Applicative f => Ap f a -> f a #