incremental-parser-0.1: Generic parser library capable of providing partial results from partial input.

Data.Monoid.Cancellative

Contents

Description

This module defines the Monoid => CancellativeMonoid => GCDMonoid class hierarchy.

Synopsis

Classes

class (LeftCancellativeMonoid m, RightCancellativeMonoid m) => CancellativeMonoid m Source

Class of monoids for which the mappend operation can be reverted while satisfying the following laws:

 mstripPrefix a (a `mappend` b) == Just b
 mstripSuffix b (a `mappend` b) == Just a
 maybe b (a `mappend`) (mstripPrefix a b) == b
 maybe b (`mappend` a) (mstripSuffix a b) == b

class (CancellativeMonoid m, LeftGCDMonoid m, RightGCDMonoid m) => GCDMonoid m Source

Class of monoids that allow the greatest common denominator to be found for any two given values. The operations must satisfy the following laws:

 commonPrefix (a `mappend` b) (a `mappend` c) == a `mappend` commonPrefix b c
 commonSuffix (a `mappend` c) (b `mappend` c) == commonSuffix a b `mappend` c

class Monoid m => LeftCancellativeMonoid m whereSource

Class of monoids with a left inverse of mappend, satisfying the following law:

 mstripPrefix a (a `mappend` b) == Just b
 maybe b (a `mappend`) (mstripPrefix a b) == b

Methods

mstripPrefix :: m -> m -> Maybe mSource

class Monoid m => RightCancellativeMonoid m whereSource

Class of monoids with a right inverse of mappend, satisfying the following law:

 mstripSuffix b (a `mappend` b) == Just a
 maybe b (`mappend` a) (mstripSuffix a b) == b

Methods

mstripSuffix :: m -> m -> Maybe mSource