free-4.2: Monads for free

Portability | GADTs, Rank2Types
Stability | provisional
Maintainer | Edward Kmett <ekmett@gmail.com>
Safe Haskell | None

Control.Applicative.Free

Description

`Applicative` functors for free

Synopsis

- data Ap f a where
  - Pure :: a -> Ap f a
  - Ap :: f a -> Ap f (a -> b) -> Ap f b
- runAp :: Applicative g => (forall x. f x -> g x) -> Ap f a -> g a
- liftAp :: f a -> Ap f a
- hoistAp :: (forall a. f a -> g a) -> Ap f b -> Ap g b
- retractAp :: Applicative f => Ap f a -> f a

# Documentation

data Ap f a where Source

The free `Applicative` for a `Functor` `f`.

Constructors

Pure :: a -> Ap f a |
Ap :: f a -> Ap f (a -> b) -> Ap f b |

Instances

Functor (Ap f) |
Typeable1 f => Typeable1 (Ap f) |
Applicative (Ap f) |
Apply (Ap f) |

runAp :: Applicative g => (forall x. f x -> g x) -> Ap f a -> g aSource

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

liftAp :: f a -> Ap f aSource

A version of `lift` that can be used with just a `Functor` for `f`.

hoistAp :: (forall a. f a -> g a) -> Ap f b -> Ap g bSource

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 aSource