Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Synopsis
- class Semigroup m => AbelianSemigroup m
- data FreeAbelianSemigroup a
- toNonEmpty :: FreeAbelianSemigroup a -> NonEmpty (a, Natural)
- fromNonEmpty :: Ord a => NonEmpty (a, Natural) -> Maybe (FreeAbelianSemigroup a)
Documentation
class Semigroup m => AbelianSemigroup m Source #
Class of commutative monoids, e.g. with additional law:
a <> b = b <> a
Instances
data FreeAbelianSemigroup a Source #
Free abelian semigroup is isomorphic to a non empty map with keys a
and
values positive natural numbers.
It is a monad on the full subcategory which satisfies the Ord
constraint,
but base does not allow to define a functor / applicative / monad
instances which are constraint by a class.
Instances
toNonEmpty :: FreeAbelianSemigroup a -> NonEmpty (a, Natural) Source #
fromNonEmpty :: Ord a => NonEmpty (a, Natural) -> Maybe (FreeAbelianSemigroup a) Source #
Smart constructor which creates FreeAbelianSemigroup
from a non empty
list of pairs (a, n) :: (a, Natural)
where n > 0
.