free-5.2: 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 :: Type -> Type) a = Alt {
  - alternatives :: [AltF f a]
  }
- data AltF (f :: Type -> Type) a where
  - Ap :: forall (f :: Type -> Type) a1 a. f a1 -> Alt f (a1 -> a) -> AltF f a
  - Pure :: forall a (f :: Type -> Type). a -> AltF f a
- runAlt :: forall f g a. 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

newtype Alt (f :: Type -> Type) a #

Constructors

Alt |
Fields alternatives :: [AltF f a]

#### Instances

Instances details

Alternative (Alt f) # |
Instance details Defined in Control.Alternative.Free Methods empty :: Alt f a # (<|>) :: Alt f a -> Alt f a -> Alt f a # some :: Alt f a -> Alt f [a] # many :: Alt f a -> Alt f [a] #
Applicative (Alt f) # |
Instance details Defined in Control.Alternative.Free Methods pure :: a -> Alt f a # (<*>) :: Alt f (a -> b) -> Alt f a -> Alt f b # liftA2 :: (a -> b -> c) -> Alt f a -> Alt f b -> Alt f c # (*>) :: Alt f a -> Alt f b -> Alt f b # (<*) :: Alt f a -> Alt f b -> Alt f a #
Functor (Alt f) # |
Instance details Defined in Control.Alternative.Free Methods fmap :: (a -> b) -> Alt f a -> Alt f b # (<$) :: a -> Alt f b -> Alt f a #
Alt (Alt f) # |
Instance details Defined in Control.Alternative.Free Methods (<!>) :: Alt f a -> Alt f a -> Alt f a # some :: Applicative (Alt f) => Alt f a -> Alt f [a] # many :: Applicative (Alt f) => Alt f a -> Alt f [a] #
Apply (Alt f) # |
Instance details Defined in Control.Alternative.Free Methods (<.>) :: Alt f (a -> b) -> Alt f a -> Alt f b # (.>) :: Alt f a -> Alt f b -> Alt f b # (<.) :: Alt f a -> Alt f b -> Alt f a # liftF2 :: (a -> b -> c) -> Alt f a -> Alt f b -> Alt f c #
Monoid (Alt f a) # |
Instance details Defined in Control.Alternative.Free Methods mempty :: Alt f a # mappend :: Alt f a -> Alt f a -> Alt f a # mconcat :: [Alt f a] -> Alt f a #
Semigroup (Alt f a) # |
Instance details Defined in Control.Alternative.Free Methods (<>) :: Alt f a -> Alt f a -> Alt f a # sconcat :: NonEmpty (Alt f a) -> Alt f a # stimes :: Integral b => b -> Alt f a -> Alt f a #

data AltF (f :: Type -> Type) a where #

Constructors

Ap :: forall (f :: Type -> Type) a1 a. f a1 -> Alt f (a1 -> a) -> AltF f a infixl 3 |
Pure :: forall a (f :: Type -> Type). a -> AltF f a |

#### Instances

Instances details

Applicative (AltF f) # |
Instance details Defined in Control.Alternative.Free Methods pure :: a -> AltF f a # (<*>) :: AltF f (a -> b) -> AltF f a -> AltF f b # liftA2 :: (a -> b -> c) -> AltF f a -> AltF f b -> AltF f c # (*>) :: AltF f a -> AltF f b -> AltF f b # (<*) :: AltF f a -> AltF f b -> AltF f a #
Functor (AltF f) # |
Instance details Defined in Control.Alternative.Free Methods fmap :: (a -> b) -> AltF f a -> AltF f b # (<$) :: a -> AltF f b -> AltF f a #

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 :: f a -> Alt f a #

A version of `lift` that can be used with any `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`.