monoid-subclasses-1.0.1: Subclasses of Monoid

Safe HaskellTrustworthy
LanguageHaskell2010

Data.Semigroup.Factorial

Contents

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

factors | foldr

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
Factorial () Source # 
Instance details

Defined in Data.Semigroup.Factorial

Methods

factors :: () -> [()] 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 #

Factorial ByteString Source # 
Instance details

Defined in Data.Semigroup.Factorial

Factorial ByteString Source # 
Instance details

Defined in Data.Semigroup.Factorial

Factorial IntSet Source # 
Instance details

Defined in Data.Semigroup.Factorial

Methods

factors :: IntSet -> [IntSet] Source #

primePrefix :: IntSet -> IntSet Source #

primeSuffix :: 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 #

length :: IntSet -> Int Source #

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

reverse :: IntSet -> IntSet Source #

Factorial Text Source # 
Instance details

Defined in Data.Semigroup.Factorial

Methods

factors :: Text -> [Text] Source #

primePrefix :: Text -> Text Source #

primeSuffix :: 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 #

length :: Text -> Int Source #

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

reverse :: Text -> Text Source #

Factorial Text Source # 
Instance details

Defined in Data.Semigroup.Factorial

Methods

factors :: Text -> [Text] Source #

primePrefix :: Text -> Text Source #

primeSuffix :: 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 #

length :: Text -> Int Source #

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

reverse :: Text -> Text Source #

Factorial ByteStringUTF8 Source # 
Instance details

Defined in Data.Monoid.Instances.ByteString.UTF8

Factorial [x] Source # 
Instance details

Defined in Data.Semigroup.Factorial

Methods

factors :: [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 details

Defined in Data.Semigroup.Factorial

Methods

factors :: 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 details

Defined in Data.Semigroup.Factorial

Methods

factors :: 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 details

Defined in Data.Semigroup.Factorial

Methods

factors :: 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 details

Defined in Data.Semigroup.Factorial

Methods

factors :: Product a -> [Product a] Source #

primePrefix :: Product a -> Product a Source #

primeSuffix :: 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 #

Factorial (IntMap a) Source # 
Instance details

Defined in Data.Semigroup.Factorial

Methods

factors :: IntMap a -> [IntMap a] Source #

primePrefix :: IntMap a -> IntMap a Source #

primeSuffix :: 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 details

Defined in Data.Semigroup.Factorial

Methods

factors :: 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 details

Defined in Data.Semigroup.Factorial

Methods

factors :: 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 #

Factorial (Vector a) Source # 
Instance details

Defined in Data.Semigroup.Factorial

Methods

factors :: Vector a -> [Vector a] Source #

primePrefix :: Vector a -> Vector a Source #

primeSuffix :: 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 #

(StableFactorial m, TextualMonoid m) => Factorial (LinePositioned m) Source # 
Instance details

Defined in Data.Monoid.Instances.Positioned

StableFactorial m => Factorial (OffsetPositioned m) Source # 
Instance details

Defined in Data.Monoid.Instances.Positioned

(StableFactorial a, MonoidNull a) => Factorial (Measured a) Source # 
Instance details

Defined in Data.Monoid.Instances.Measured

Methods

factors :: Measured a -> [Measured a] Source #

primePrefix :: Measured a -> Measured a Source #

primeSuffix :: 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 #

reverse :: Measured a -> Measured a Source #

(Factorial a, PositiveMonoid a) => Factorial (Concat a) Source # 
Instance details

Defined in Data.Monoid.Instances.Concat

Methods

factors :: Concat a -> [Concat a] Source #

primePrefix :: Concat a -> Concat a Source #

primeSuffix :: 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 details

Defined in Data.Semigroup.Factorial

Methods

factors :: (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 details

Defined in Data.Semigroup.Factorial

Methods

factors :: 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 details

Defined in Data.Monoid.Instances.Stateful

Methods

factors :: 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 details

Defined in Data.Semigroup.Factorial

Methods

factors :: (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 details

Defined in Data.Semigroup.Factorial

Methods

factors :: (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
StableFactorial () Source # 
Instance details

Defined in Data.Semigroup.Factorial

StableFactorial ByteString Source # 
Instance details

Defined in Data.Semigroup.Factorial

StableFactorial ByteString Source # 
Instance details

Defined in Data.Semigroup.Factorial

StableFactorial Text Source # 
Instance details

Defined in Data.Semigroup.Factorial

StableFactorial Text Source # 
Instance details

Defined in Data.Semigroup.Factorial

StableFactorial [x] Source # 
Instance details

Defined in Data.Semigroup.Factorial

StableFactorial a => StableFactorial (Dual a) Source # 
Instance details

Defined in Data.Semigroup.Factorial

StableFactorial (Sum Natural) Source # 
Instance details

Defined in Data.Semigroup.Factorial

StableFactorial (Seq a) Source # 
Instance details

Defined in Data.Semigroup.Factorial

StableFactorial (Vector a) Source # 
Instance details

Defined in Data.Semigroup.Factorial

(StableFactorial m, TextualMonoid m) => StableFactorial (LinePositioned m) Source # 
Instance details

Defined in Data.Monoid.Instances.Positioned

StableFactorial m => StableFactorial (OffsetPositioned m) Source # 
Instance details

Defined in Data.Monoid.Instances.Positioned

(StableFactorial a, MonoidNull a) => StableFactorial (Measured a) Source # 
Instance details

Defined in Data.Monoid.Instances.Measured

(Factorial a, PositiveMonoid a) => StableFactorial (Concat a) Source # 
Instance details

Defined in Data.Monoid.Instances.Concat

(FactorialMonoid a, FactorialMonoid b, StableFactorial a, StableFactorial b) => StableFactorial (Stateful a b) Source # 
Instance details

Defined in Data.Monoid.Instances.Stateful

Monad function equivalents

mapM :: (Factorial a, Monoid b, Monad m) => (a -> m b) -> a -> m b Source #

A mapM equivalent.

mapM_ :: (Factorial a, Applicative m) => (a -> m b) -> a -> m () Source #

A mapM_ equivalent.