monoid-subclasses-1.0.1: Subclasses of Monoid

Data.Semigroup.Factorial

Description

This module defines the Semigroup => Factorial => StableFactorial classes and some of their instances.

Synopsis

# Classes

class Semigroup m => Factorial m where Source #

Class of semigroups that can be split into irreducible (i.e., atomic or prime) factors in a unique way. Factors of a Product are literally its prime factors:

factors (Product 12) == [Product 2, Product 2, Product 3]

Factors of a list are not its elements but all its single-item sublists:

factors "abc" == ["a", "b", "c"]

The methods of this class satisfy the following laws:

maybe id sconcat  . nonEmpty . factors == id
List.all (\prime-> factors prime == [prime]) . factors
factors . reverse == List.reverse . factors
primePrefix s == foldr const s s
primeSuffix s == primePrefix (reverse s)
foldl f a == List.foldl f a . factors
foldl' f a == List.foldl' f a . factors
foldr f a == List.foldr f a . factors

A minimal instance definition must implement factors or foldr. Other methods can and should be implemented only for performance reasons.

Minimal complete definition

Methods

factors :: m -> [m] Source #

Returns a list of all prime factors; inverse of mconcat.

primePrefix :: m -> m Source #

The prime prefix; primePrefix mempty == mempty for monoids.

primeSuffix :: m -> m Source #

The prime suffix; primeSuffix mempty == mempty for monoids.

foldl :: (a -> m -> a) -> a -> m -> a Source #

Like foldl from Data.List on the list of prime factors.

foldl' :: (a -> m -> a) -> a -> m -> a Source #

Like foldl' from Data.List on the list of prime factors.

foldr :: (m -> a -> a) -> a -> m -> a Source #

Like foldr from Data.List on the list of prime factors.

length :: m -> Int Source #

The length of the list of prime factors.

foldMap :: Monoid n => (m -> n) -> m -> n Source #

Generalizes foldMap from Data.Foldable, except the function arguments are prime factors rather than the structure elements.

reverse :: m -> m Source #

Equivalent to reverse from Data.List.

Instances
 Source # Instance detailsDefined in Data.Semigroup.Factorial Methodsfactors :: () -> [()] Source #primePrefix :: () -> () Source #primeSuffix :: () -> () Source #foldl :: (a -> () -> a) -> a -> () -> a Source #foldl' :: (a -> () -> a) -> a -> () -> a Source #foldr :: (() -> a -> a) -> a -> () -> a Source #length :: () -> Int Source #foldMap :: Monoid n => (() -> n) -> () -> n Source #reverse :: () -> () Source # Source # Instance detailsDefined in Data.Semigroup.Factorial Methodsfoldl :: (a -> ByteString -> a) -> a -> ByteString -> a Source #foldl' :: (a -> ByteString -> a) -> a -> ByteString -> a Source #foldr :: (ByteString -> a -> a) -> a -> ByteString -> a Source #foldMap :: Monoid n => (ByteString -> n) -> ByteString -> n Source # Source # Instance detailsDefined in Data.Semigroup.Factorial Methodsfoldl :: (a -> ByteString -> a) -> a -> ByteString -> a Source #foldl' :: (a -> ByteString -> a) -> a -> ByteString -> a Source #foldr :: (ByteString -> a -> a) -> a -> ByteString -> a Source #foldMap :: Monoid n => (ByteString -> n) -> ByteString -> n Source # Source # Instance detailsDefined in Data.Semigroup.Factorial Methodsfactors :: IntSet -> [IntSet] Source #foldl :: (a -> IntSet -> a) -> a -> IntSet -> a Source #foldl' :: (a -> IntSet -> a) -> a -> IntSet -> a Source #foldr :: (IntSet -> a -> a) -> a -> IntSet -> a Source #foldMap :: Monoid n => (IntSet -> n) -> IntSet -> n Source # Source # Instance detailsDefined in Data.Semigroup.Factorial Methodsfactors :: Text -> [Text] Source #foldl :: (a -> Text -> a) -> a -> Text -> a Source #foldl' :: (a -> Text -> a) -> a -> Text -> a Source #foldr :: (Text -> a -> a) -> a -> Text -> a Source #foldMap :: Monoid n => (Text -> n) -> Text -> n Source # Source # Instance detailsDefined in Data.Semigroup.Factorial Methodsfactors :: Text -> [Text] Source #foldl :: (a -> Text -> a) -> a -> Text -> a Source #foldl' :: (a -> Text -> a) -> a -> Text -> a Source #foldr :: (Text -> a -> a) -> a -> Text -> a Source #foldMap :: Monoid n => (Text -> n) -> Text -> n Source # Source # Instance detailsDefined in Data.Monoid.Instances.ByteString.UTF8 Methodsfoldl :: (a -> ByteStringUTF8 -> a) -> a -> ByteStringUTF8 -> a Source #foldl' :: (a -> ByteStringUTF8 -> a) -> a -> ByteStringUTF8 -> a Source #foldr :: (ByteStringUTF8 -> a -> a) -> a -> ByteStringUTF8 -> a Source #foldMap :: Monoid n => (ByteStringUTF8 -> n) -> ByteStringUTF8 -> n Source # Factorial [x] Source # Instance detailsDefined in Data.Semigroup.Factorial Methodsfactors :: [x] -> [[x]] Source #primePrefix :: [x] -> [x] Source #primeSuffix :: [x] -> [x] Source #foldl :: (a -> [x] -> a) -> a -> [x] -> a Source #foldl' :: (a -> [x] -> a) -> a -> [x] -> a Source #foldr :: ([x] -> a -> a) -> a -> [x] -> a Source #length :: [x] -> Int Source #foldMap :: Monoid n => ([x] -> n) -> [x] -> n Source #reverse :: [x] -> [x] Source # Factorial a => Factorial (Maybe a) Source # Instance detailsDefined in Data.Semigroup.Factorial Methodsfactors :: Maybe a -> [Maybe a] Source #primePrefix :: Maybe a -> Maybe a Source #primeSuffix :: Maybe a -> Maybe a Source #foldl :: (a0 -> Maybe a -> a0) -> a0 -> Maybe a -> a0 Source #foldl' :: (a0 -> Maybe a -> a0) -> a0 -> Maybe a -> a0 Source #foldr :: (Maybe a -> a0 -> a0) -> a0 -> Maybe a -> a0 Source #length :: Maybe a -> Int Source #foldMap :: Monoid n => (Maybe a -> n) -> Maybe a -> n Source #reverse :: Maybe a -> Maybe a Source # Factorial a => Factorial (Dual a) Source # Instance detailsDefined in Data.Semigroup.Factorial Methodsfactors :: Dual a -> [Dual a] Source #primePrefix :: Dual a -> Dual a Source #primeSuffix :: Dual a -> Dual a Source #foldl :: (a0 -> Dual a -> a0) -> a0 -> Dual a -> a0 Source #foldl' :: (a0 -> Dual a -> a0) -> a0 -> Dual a -> a0 Source #foldr :: (Dual a -> a0 -> a0) -> a0 -> Dual a -> a0 Source #length :: Dual a -> Int Source #foldMap :: Monoid n => (Dual a -> n) -> Dual a -> n Source #reverse :: Dual a -> Dual a Source # (Integral a, Eq a) => Factorial (Sum a) Source # Instance detailsDefined in Data.Semigroup.Factorial Methodsfactors :: Sum a -> [Sum a] Source #primePrefix :: Sum a -> Sum a Source #primeSuffix :: Sum a -> Sum a Source #foldl :: (a0 -> Sum a -> a0) -> a0 -> Sum a -> a0 Source #foldl' :: (a0 -> Sum a -> a0) -> a0 -> Sum a -> a0 Source #foldr :: (Sum a -> a0 -> a0) -> a0 -> Sum a -> a0 Source #length :: Sum a -> Int Source #foldMap :: Monoid n => (Sum a -> n) -> Sum a -> n Source #reverse :: Sum a -> Sum a Source # Integral a => Factorial (Product a) Source # Instance detailsDefined in Data.Semigroup.Factorial Methodsfactors :: Product a -> [Product a] Source #foldl :: (a0 -> Product a -> a0) -> a0 -> Product a -> a0 Source #foldl' :: (a0 -> Product a -> a0) -> a0 -> Product a -> a0 Source #foldr :: (Product a -> a0 -> a0) -> a0 -> Product a -> a0 Source #length :: Product a -> Int Source #foldMap :: Monoid n => (Product a -> n) -> Product a -> n Source #reverse :: Product a -> Product a Source # Source # Instance detailsDefined in Data.Semigroup.Factorial Methodsfactors :: IntMap a -> [IntMap a] Source #foldl :: (a0 -> IntMap a -> a0) -> a0 -> IntMap a -> a0 Source #foldl' :: (a0 -> IntMap a -> a0) -> a0 -> IntMap a -> a0 Source #foldr :: (IntMap a -> a0 -> a0) -> a0 -> IntMap a -> a0 Source #length :: IntMap a -> Int Source #foldMap :: Monoid n => (IntMap a -> n) -> IntMap a -> n Source #reverse :: IntMap a -> IntMap a Source # Factorial (Seq a) Source # Instance detailsDefined in Data.Semigroup.Factorial Methodsfactors :: Seq a -> [Seq a] Source #primePrefix :: Seq a -> Seq a Source #primeSuffix :: Seq a -> Seq a Source #foldl :: (a0 -> Seq a -> a0) -> a0 -> Seq a -> a0 Source #foldl' :: (a0 -> Seq a -> a0) -> a0 -> Seq a -> a0 Source #foldr :: (Seq a -> a0 -> a0) -> a0 -> Seq a -> a0 Source #length :: Seq a -> Int Source #foldMap :: Monoid n => (Seq a -> n) -> Seq a -> n Source #reverse :: Seq a -> Seq a Source # Ord a => Factorial (Set a) Source # Instance detailsDefined in Data.Semigroup.Factorial Methodsfactors :: Set a -> [Set a] Source #primePrefix :: Set a -> Set a Source #primeSuffix :: Set a -> Set a Source #foldl :: (a0 -> Set a -> a0) -> a0 -> Set a -> a0 Source #foldl' :: (a0 -> Set a -> a0) -> a0 -> Set a -> a0 Source #foldr :: (Set a -> a0 -> a0) -> a0 -> Set a -> a0 Source #length :: Set a -> Int Source #foldMap :: Monoid n => (Set a -> n) -> Set a -> n Source #reverse :: Set a -> Set a Source # Source # Instance detailsDefined in Data.Semigroup.Factorial Methodsfactors :: Vector a -> [Vector a] Source #foldl :: (a0 -> Vector a -> a0) -> a0 -> Vector a -> a0 Source #foldl' :: (a0 -> Vector a -> a0) -> a0 -> Vector a -> a0 Source #foldr :: (Vector a -> a0 -> a0) -> a0 -> Vector a -> a0 Source #length :: Vector a -> Int Source #foldMap :: Monoid n => (Vector a -> n) -> Vector a -> n Source #reverse :: Vector a -> Vector a Source # Source # Instance detailsDefined in Data.Monoid.Instances.Positioned Methodsfoldl :: (a -> LinePositioned m -> a) -> a -> LinePositioned m -> a Source #foldl' :: (a -> LinePositioned m -> a) -> a -> LinePositioned m -> a Source #foldr :: (LinePositioned m -> a -> a) -> a -> LinePositioned m -> a Source #foldMap :: Monoid n => (LinePositioned m -> n) -> LinePositioned m -> n Source # Source # Instance detailsDefined in Data.Monoid.Instances.Positioned Methodsfoldl :: (a -> OffsetPositioned m -> a) -> a -> OffsetPositioned m -> a Source #foldl' :: (a -> OffsetPositioned m -> a) -> a -> OffsetPositioned m -> a Source #foldr :: (OffsetPositioned m -> a -> a) -> a -> OffsetPositioned m -> a Source #foldMap :: Monoid n => (OffsetPositioned m -> n) -> OffsetPositioned m -> n Source # (StableFactorial a, MonoidNull a) => Factorial (Measured a) Source # Instance detailsDefined in Data.Monoid.Instances.Measured Methodsfactors :: Measured a -> [Measured a] Source #foldl :: (a0 -> Measured a -> a0) -> a0 -> Measured a -> a0 Source #foldl' :: (a0 -> Measured a -> a0) -> a0 -> Measured a -> a0 Source #foldr :: (Measured a -> a0 -> a0) -> a0 -> Measured a -> a0 Source #length :: Measured a -> Int Source #foldMap :: Monoid n => (Measured a -> n) -> Measured a -> n Source # (Factorial a, PositiveMonoid a) => Factorial (Concat a) Source # Instance detailsDefined in Data.Monoid.Instances.Concat Methodsfactors :: Concat a -> [Concat a] Source #foldl :: (a0 -> Concat a -> a0) -> a0 -> Concat a -> a0 Source #foldl' :: (a0 -> Concat a -> a0) -> a0 -> Concat a -> a0 Source #foldr :: (Concat a -> a0 -> a0) -> a0 -> Concat a -> a0 Source #length :: Concat a -> Int Source #foldMap :: Monoid n => (Concat a -> n) -> Concat a -> n Source #reverse :: Concat a -> Concat a Source # (Factorial a, Factorial b, MonoidNull a, MonoidNull b) => Factorial (a, b) Source # Instance detailsDefined in Data.Semigroup.Factorial Methodsfactors :: (a, b) -> [(a, b)] Source #primePrefix :: (a, b) -> (a, b) Source #primeSuffix :: (a, b) -> (a, b) Source #foldl :: (a0 -> (a, b) -> a0) -> a0 -> (a, b) -> a0 Source #foldl' :: (a0 -> (a, b) -> a0) -> a0 -> (a, b) -> a0 Source #foldr :: ((a, b) -> a0 -> a0) -> a0 -> (a, b) -> a0 Source #length :: (a, b) -> Int Source #foldMap :: Monoid n => ((a, b) -> n) -> (a, b) -> n Source #reverse :: (a, b) -> (a, b) Source # Ord k => Factorial (Map k v) Source # Instance detailsDefined in Data.Semigroup.Factorial Methodsfactors :: Map k v -> [Map k v] Source #primePrefix :: Map k v -> Map k v Source #primeSuffix :: Map k v -> Map k v Source #foldl :: (a -> Map k v -> a) -> a -> Map k v -> a Source #foldl' :: (a -> Map k v -> a) -> a -> Map k v -> a Source #foldr :: (Map k v -> a -> a) -> a -> Map k v -> a Source #length :: Map k v -> Int Source #foldMap :: Monoid n => (Map k v -> n) -> Map k v -> n Source #reverse :: Map k v -> Map k v Source # (FactorialMonoid a, FactorialMonoid b) => Factorial (Stateful a b) Source # Instance detailsDefined in Data.Monoid.Instances.Stateful Methodsfactors :: Stateful a b -> [Stateful a b] Source #primePrefix :: Stateful a b -> Stateful a b Source #primeSuffix :: Stateful a b -> Stateful a b Source #foldl :: (a0 -> Stateful a b -> a0) -> a0 -> Stateful a b -> a0 Source #foldl' :: (a0 -> Stateful a b -> a0) -> a0 -> Stateful a b -> a0 Source #foldr :: (Stateful a b -> a0 -> a0) -> a0 -> Stateful a b -> a0 Source #length :: Stateful a b -> Int Source #foldMap :: Monoid n => (Stateful a b -> n) -> Stateful a b -> n Source #reverse :: Stateful a b -> Stateful a b Source # (Factorial a, Factorial b, Factorial c, MonoidNull a, MonoidNull b, MonoidNull c) => Factorial (a, b, c) Source # Instance detailsDefined in Data.Semigroup.Factorial Methodsfactors :: (a, b, c) -> [(a, b, c)] Source #primePrefix :: (a, b, c) -> (a, b, c) Source #primeSuffix :: (a, b, c) -> (a, b, c) Source #foldl :: (a0 -> (a, b, c) -> a0) -> a0 -> (a, b, c) -> a0 Source #foldl' :: (a0 -> (a, b, c) -> a0) -> a0 -> (a, b, c) -> a0 Source #foldr :: ((a, b, c) -> a0 -> a0) -> a0 -> (a, b, c) -> a0 Source #length :: (a, b, c) -> Int Source #foldMap :: Monoid n => ((a, b, c) -> n) -> (a, b, c) -> n Source #reverse :: (a, b, c) -> (a, b, c) Source # (Factorial a, Factorial b, Factorial c, Factorial d, MonoidNull a, MonoidNull b, MonoidNull c, MonoidNull d) => Factorial (a, b, c, d) Source # Instance detailsDefined in Data.Semigroup.Factorial Methodsfactors :: (a, b, c, d) -> [(a, b, c, d)] Source #primePrefix :: (a, b, c, d) -> (a, b, c, d) Source #primeSuffix :: (a, b, c, d) -> (a, b, c, d) Source #foldl :: (a0 -> (a, b, c, d) -> a0) -> a0 -> (a, b, c, d) -> a0 Source #foldl' :: (a0 -> (a, b, c, d) -> a0) -> a0 -> (a, b, c, d) -> a0 Source #foldr :: ((a, b, c, d) -> a0 -> a0) -> a0 -> (a, b, c, d) -> a0 Source #length :: (a, b, c, d) -> Int Source #foldMap :: Monoid n => ((a, b, c, d) -> n) -> (a, b, c, d) -> n Source #reverse :: (a, b, c, d) -> (a, b, c, d) Source #

class Factorial m => StableFactorial m Source #

A subclass of Factorial whose instances satisfy this additional law:

factors (a <> b) == factors a <> factors b
Instances
 Source # Instance detailsDefined in Data.Semigroup.Factorial Source # Instance detailsDefined in Data.Semigroup.Factorial Source # Instance detailsDefined in Data.Semigroup.Factorial Source # Instance detailsDefined in Data.Semigroup.Factorial Source # Instance detailsDefined in Data.Semigroup.Factorial Source # Instance detailsDefined in Data.Semigroup.Factorial Source # Instance detailsDefined in Data.Semigroup.Factorial Source # Instance detailsDefined in Data.Semigroup.Factorial Source # Instance detailsDefined in Data.Semigroup.Factorial Source # Instance detailsDefined in Data.Semigroup.Factorial Source # Instance detailsDefined in Data.Monoid.Instances.Positioned Source # Instance detailsDefined in Data.Monoid.Instances.Positioned Source # Instance detailsDefined in Data.Monoid.Instances.Measured (Factorial a, PositiveMonoid a) => StableFactorial (Concat a) Source # Instance detailsDefined in Data.Monoid.Instances.Concat Source # Instance detailsDefined in Data.Monoid.Instances.Stateful

A mapM equivalent.
A mapM_ equivalent.