Control.Alternative.Free

free-4.12.4: Monads for free

Copyright | (C) 2012 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

Control.Alternative.Free

Description

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

Synopsis

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

# Documentation

newtype Alt f a

Constructors

Alt |
Fields alternatives :: [AltF f a]

Instances

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

data AltF f a where

Constructors

Ap :: f a -> Alt f (a -> b) -> AltF f b infixl 3 |
Pure :: a -> AltF f a |

Instances

Functor f => Functor (AltF f) |
Functor f => Applicative (AltF f) |

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

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

liftAlt :: Functor f => f a -> Alt f a

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 b

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