Copyright | (c) 2020-2021 Reed Mullanix Emily Pillmore |
---|---|

License | BSD-style |

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

Stability | stable |

Portability | non-portable |

Safe Haskell | Safe |

Language | Haskell2010 |

This module provides definitions `GroupFoldable`

,
along with useful combinators.

## Synopsis

- class GroupFoldable t where
- gold :: (GroupFoldable t, Group g) => t g -> g
- goldr :: GroupFoldable t => Group g => (a -> Permutation g) -> t a -> Permutation g
- toFreeGroup :: (GroupFoldable t, Group g) => t g -> FreeGroup g

# Group foldable

class GroupFoldable t where Source #

The class of data structures that can be groupoidally folded.

`GroupFoldable`

has difficult-to-define laws in terms of Haskell,
but is well-understood categorically: `GroupFoldable`

s are
functors (not necessarily `Functor`

s) in the slice category \( [\mathcal{Hask}, \mathcal{Hask}] / F \),
where \( F \) is the free group functor. Hence, they are
defined by the natural transformations \( [\mathcal{Hask},\mathcal{Hask}](-, F) \) - i.e. `toFG`

, or `toFreeGroup`

.

goldMap :: Group g => (a -> g) -> t a -> g Source #

Apply a `Group`

fold to some container.

This function takes a container that can be represented as a
`FreeGroup`

, and simplifies the container as a word in the
free group, producing a final output according to some
mapping of elements into the target group.

The name is a pun on `Group`

and `fold`

.

**Examples**:

`>>>`

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

`>>>`

Sum {getSum = 2}`goldMap id x`

`>>>`

Sum {getSum = 3}`goldMap (\a -> if a < 2 then mempty else a) x`

Translate a `GroupFoldable`

container into a Church-encoded
free group.

Analagous to `toList`

for `Foldable`

, if `toList`

respected the
associativity of ⊥.

#### Instances

GroupFoldable Identity Source # | |

GroupFoldable Dual Source # | |

GroupFoldable Sum Source # | |

GroupFoldable Product Source # | |

GroupFoldable Abelianizer Source # | |

Defined in Data.Group.Foldable goldMap :: Group g => (a -> g) -> Abelianizer a -> g Source # toFG :: Abelianizer a -> FG a Source # | |

GroupFoldable FreeGroup Source # | |

GroupFoldable FG Source # | |

GroupFoldable (Const a :: Type -> Type) Source # | |

(GroupFoldable f, GroupFoldable g) => GroupFoldable (f :+: g) Source # | |

(GroupFoldable f, GroupFoldable g) => GroupFoldable (f :*: g) Source # | |

(GroupFoldable f, GroupFoldable g) => GroupFoldable (f :.: g) Source # | |

(GroupFoldable f, GroupFoldable g) => GroupFoldable (Compose f g) Source # | |

## Group foldable combinators

gold :: (GroupFoldable t, Group g) => t g -> g Source #

Simplify a word in `GroupFoldable`

container as a word
in a `FreeGroup`

.

The name is a pun on `Group`

and `fold`

.

**Examples**:

`>>>`

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

`>>>`

Sum {getSum = 2}`gold x`

goldr :: GroupFoldable t => Group g => (a -> Permutation g) -> t a -> Permutation g Source #

A right group fold from a `GroupFoldable`

container to its permutation group

toFreeGroup :: (GroupFoldable t, Group g) => t g -> FreeGroup g Source #

Convert a `GroupFoldable`

container into a `FreeGroup`