Copyright | (c) 2020 Emily Pillmore |
---|---|

License | BSD-style |

Maintainer | Emily Pillmore <emilypi@cohomolo.gy>, Reed Mullanix <reedmullanix@gmail.com> |

Stability | stable |

Portability | non-portable |

Safe Haskell | Safe |

Language | Haskell2010 |

This module contains definitions for `Cancelative`

functors
along with the relevant combinators.

## Synopsis

- class Alternative f => Cancelative f where
- cancel :: f a -> f a

- cancel1 :: (Group a, Cancelative f) => a -> f a -> f a
- annihalate :: (Cancelative f, Traversable t) => (a -> f a) -> t a -> f (t a)

# Cancelative

class Alternative f => Cancelative f where Source #

A group on `Applicative`

functors.

`Cancelative`

functors have the following laws:

This is analogous to a group operation on applicative functors,
in the sense that `Alternative`

forms a monoid. A straight-
forward implementation exists whenever `f a`

forms a `Group`

for all `a`

, in which case, `cancel == invert`

.

Invert (or `cancel`

) a `Cancelative`

functor, such that, if the
functor is also a `GroupFoldable`

, then

amounts to evaluating the inverse of a word in the functor.`gold`

`.`

`cancel`

### Examples:

`>>>`

`let x = FreeGroup [Left (Sum (2 :: Word8)), Right (Sum 3)]`

`>>>`

FreeGroup {runFreeGroup = [Right (Sum {getSum = 2}),Left (Sum {getSum = 3})]}`cancel x`

#### Instances

Cancelative FreeGroup Source # | |

Cancelative FA Source # | |

Cancelative FG Source # | |

Cancelative (Proxy :: Type -> Type) Source # | |

## Cancelative combinators

cancel1 :: (Group a, Cancelative f) => a -> f a -> f a Source #

Cancel a single element in a `Cancelative`

functor.

### Examples:

`>>>`

`let x = FreeGroup [Left (Sum (2 :: Word8)), Right (Sum 3)]`

`>>>`

Sum {getSum = 1}`gold x`

`>>>`

Sum {getSum = 0}`gold $ cancel1 (Sum 1) x`

annihalate :: (Cancelative f, Traversable t) => (a -> f a) -> t a -> f (t a) Source #

Annihalate a `Traversable'`

s worth of elements in a `Cancelative`

functor.