group-theory-0.2.2: The theory of groups
Copyright(c) 2020 Emily Pillmore
LicenseBSD-style
MaintainerEmily Pillmore <emilypi@cohomolo.gy>, Reed Mullanix <reedmullanix@gmail.com>
Stabilitystable
Portabilitynon-portable
Safe HaskellSafe
LanguageHaskell2010

Control.Applicative.Cancellative

Description

This module contains definitions for Cancellative functors along with the relevant combinators.

Synopsis

Cancellative

class Alternative f => Cancellative f where Source #

A group on Applicative functors.

Cancellative functors have the following laws in addition to those of Alternative:

Left Cancellation
cancel a <|> a = empty
Rigth Cancellation
a <|> cancel a = empty

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.

Minimal complete definition

Nothing

Methods

cancel :: f a -> f a Source #

Invert (or cancel) a Cancellative functor, such that, if the functor is also a GroupFoldable, then gold . cancel amounts to evaluating the inverse of a word in the functor.

Examples:

Expand
>>> let x = FreeGroup [Left (Sum (2 :: Word8)), Right (Sum 3)]
>>> cancel x
FreeGroup {runFreeGroup = [Left (Sum {getSum = 3}),Right (Sum {getSum = 2})]}

default cancel :: Group (f a) => f a -> f a Source #

Instances

Instances details
Cancellative FreeGroup Source # 
Instance details

Defined in Control.Applicative.Cancellative

Methods

cancel :: FreeGroup a -> FreeGroup a Source #

Cancellative FA Source # 
Instance details

Defined in Control.Applicative.Cancellative

Methods

cancel :: FA a -> FA a Source #

Cancellative FG Source # 
Instance details

Defined in Control.Applicative.Cancellative

Methods

cancel :: FG a -> FG a Source #

Cancellative (Proxy :: Type -> Type) Source # 
Instance details

Defined in Control.Applicative.Cancellative

Methods

cancel :: Proxy a -> Proxy a Source #

Cancellative combinators

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

Cancel a single element in a Cancellative functor.

Examples:

Expand
>>> let x = FreeGroup [Left (Sum (2 :: Word8)), Right (Sum 3)]
>>> gold x
Sum {getSum = 1}
>>> gold $ cancel1 (Sum 1) x
Sum {getSum = 0}

annihilate :: (Cancellative f, Traversable t) => (a -> f a) -> t a -> f (t a) Source #

Annihilate a Traversable's worth of elements in a Cancellative functor.