free-4.2: Monads for free

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

Control.Alternative.Free

Description

Left distributive `Alternative` functors for free, based on a design by Stijn van Drongelen.

Synopsis

- data Alt f a where
  - Pure :: a -> Alt f a
  - Ap :: f a -> Alt f (a -> b) -> Alt f b
  - Alt :: [Alt f a] -> Alt f a
- runAlt :: Alternative g => (forall x. f x -> g x) -> Alt f a -> g a
- liftAlt :: f a -> Alt f a
- hoistAlt :: (forall a. f a -> g a) -> Alt f b -> Alt g b

# Documentation

data Alt f a where Source

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

Constructors

Pure :: a -> Alt f a |
Ap :: f a -> Alt f (a -> b) -> Alt f b |
Alt :: [Alt f a] -> Alt f a |

Instances

Functor (Alt f) |
Typeable1 f => Typeable1 (Alt f) |
Applicative (Alt f) |
Alternative (Alt f) |
Apply (Alt f) |
Monoid (Alt f a) |
Semigroup (Alt f a) |

runAlt :: Alternative g => (forall x. f x -> g x) -> Alt f a -> g aSource

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

liftAlt :: f a -> Alt f aSource

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

hoistAlt :: (forall a. f a -> g a) -> Alt f b -> Alt g bSource

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