semigroups-0.18.1: Anything that associates

Data.Semigroup

Description

In mathematics, a semigroup is an algebraic structure consisting of a set together with an associative binary operation. A semigroup generalizes a monoid in that there might not exist an identity element. It also (originally) generalized a group (a monoid with all inverses) to a type where every element did not have to have an inverse, thus the name semigroup.

The use of `(<>)` in this module conflicts with an operator with the same name that is being exported by Data.Monoid. However, this package re-exports (most of) the contents of Data.Monoid, so to use semigroups and monoids in the same package just

`import Data.Semigroup`

Synopsis

# Documentation

class Semigroup a where Source

Minimal complete definition

Nothing

Methods

(<>) :: a -> a -> a infixr 6 Source

An associative operation.

```(a `<>` b) `<>` c = a `<>` (b `<>` c)
```

If `a` is also a `Monoid` we further require

```(`<>`) = `mappend`
```

sconcat :: NonEmpty a -> a Source

Reduce a non-empty list with `<>`

The default definition should be sufficient, but this can be overridden for efficiency.

stimes :: Integral b => b -> a -> a Source

Repeat a value `n` times.

Given that this works on a `Semigroup` it is allowed to fail if you request 0 or fewer repetitions, and the default definition will do so.

By making this a member of the class, idempotent semigroups and monoids can upgrade this to execute in O(1) by picking `stimes = stimesIdempotent` or `stimes = stimesIdempotentMonoid` respectively.

Since: 0.17

Instances

 Source Methodsstimes :: Integral b => b -> Ordering -> Ordering Source Source Methods(<>) :: () -> () -> () Sourcesconcat :: NonEmpty () -> () Sourcestimes :: Integral b => b -> () -> () Source Source Methods(<>) :: Void -> Void -> Void Sourcestimes :: Integral b => b -> Void -> Void Source Source Methods(<>) :: All -> All -> All Sourcestimes :: Integral b => b -> All -> All Source Source Methods(<>) :: Any -> Any -> Any Sourcestimes :: Integral b => b -> Any -> Any Source Source Methodsstimes :: Integral b => b -> ByteString -> ByteString Source Source Methodsstimes :: Integral b => b -> ByteString -> ByteString Source Source Methodsstimes :: Integral b => b -> Builder -> Builder Source Source Methodsstimes :: Integral b => b -> Builder -> Builder Source Source Methodsstimes :: Integral b => b -> ShortByteString -> ShortByteString Source Source Methodsstimes :: Integral b => b -> IntSet -> IntSet Source Source Methodsstimes :: Integral b => b -> Builder -> Builder Source Source Methods(<>) :: Text -> Text -> Text Sourcestimes :: Integral b => b -> Text -> Text Source Source Methods(<>) :: Text -> Text -> Text Sourcestimes :: Integral b => b -> Text -> Text Source Semigroup [a] Source Methods(<>) :: [a] -> [a] -> [a] Sourcesconcat :: NonEmpty [a] -> [a] Sourcestimes :: Integral b => b -> [a] -> [a] Source Semigroup a => Semigroup (Identity a) Source Methods(<>) :: Identity a -> Identity a -> Identity a Sourcestimes :: Integral b => b -> Identity a -> Identity a Source Semigroup a => Semigroup (Dual a) Source Methods(<>) :: Dual a -> Dual a -> Dual a Sourcesconcat :: NonEmpty (Dual a) -> Dual a Sourcestimes :: Integral b => b -> Dual a -> Dual a Source Source Methods(<>) :: Endo a -> Endo a -> Endo a Sourcesconcat :: NonEmpty (Endo a) -> Endo a Sourcestimes :: Integral b => b -> Endo a -> Endo a Source Num a => Semigroup (Sum a) Source Methods(<>) :: Sum a -> Sum a -> Sum a Sourcesconcat :: NonEmpty (Sum a) -> Sum a Sourcestimes :: Integral b => b -> Sum a -> Sum a Source Num a => Semigroup (Product a) Source Methods(<>) :: Product a -> Product a -> Product a Sourcesconcat :: NonEmpty (Product a) -> Product a Sourcestimes :: Integral b => b -> Product a -> Product a Source Source Methods(<>) :: First a -> First a -> First a Sourcesconcat :: NonEmpty (First a) -> First a Sourcestimes :: Integral b => b -> First a -> First a Source Source Methods(<>) :: Last a -> Last a -> Last a Sourcesconcat :: NonEmpty (Last a) -> Last a Sourcestimes :: Integral b => b -> Last a -> Last a Source Semigroup a => Semigroup (Maybe a) Source Methods(<>) :: Maybe a -> Maybe a -> Maybe a Sourcesconcat :: NonEmpty (Maybe a) -> Maybe a Sourcestimes :: Integral b => b -> Maybe a -> Maybe a Source Source Methods(<>) :: IntMap v -> IntMap v -> IntMap v Sourcesconcat :: NonEmpty (IntMap v) -> IntMap v Sourcestimes :: Integral b => b -> IntMap v -> IntMap v Source Ord a => Semigroup (Set a) Source Methods(<>) :: Set a -> Set a -> Set a Sourcesconcat :: NonEmpty (Set a) -> Set a Sourcestimes :: Integral b => b -> Set a -> Set a Source Semigroup (Seq a) Source Methods(<>) :: Seq a -> Seq a -> Seq a Sourcesconcat :: NonEmpty (Seq a) -> Seq a Sourcestimes :: Integral b => b -> Seq a -> Seq a Source (Hashable a, Eq a) => Semigroup (HashSet a) Source Methods(<>) :: HashSet a -> HashSet a -> HashSet a Sourcesconcat :: NonEmpty (HashSet a) -> HashSet a Sourcestimes :: Integral b => b -> HashSet a -> HashSet a Source Source Methods(<>) :: NonEmpty a -> NonEmpty a -> NonEmpty a Sourcestimes :: Integral b => b -> NonEmpty a -> NonEmpty a Source Semigroup a => Semigroup (Option a) Source Methods(<>) :: Option a -> Option a -> Option a Sourcesconcat :: NonEmpty (Option a) -> Option a Sourcestimes :: Integral b => b -> Option a -> Option a Source Monoid m => Semigroup (WrappedMonoid m) Source Methodsstimes :: Integral b => b -> WrappedMonoid m -> WrappedMonoid m Source Source Methods(<>) :: Last a -> Last a -> Last a Sourcesconcat :: NonEmpty (Last a) -> Last a Sourcestimes :: Integral b => b -> Last a -> Last a Source Source Methods(<>) :: First a -> First a -> First a Sourcesconcat :: NonEmpty (First a) -> First a Sourcestimes :: Integral b => b -> First a -> First a Source Ord a => Semigroup (Max a) Source Methods(<>) :: Max a -> Max a -> Max a Sourcesconcat :: NonEmpty (Max a) -> Max a Sourcestimes :: Integral b => b -> Max a -> Max a Source Ord a => Semigroup (Min a) Source Methods(<>) :: Min a -> Min a -> Min a Sourcesconcat :: NonEmpty (Min a) -> Min a Sourcestimes :: Integral b => b -> Min a -> Min a Source Semigroup b => Semigroup (a -> b) Source Methods(<>) :: (a -> b) -> (a -> b) -> a -> b Sourcesconcat :: NonEmpty (a -> b) -> a -> b Sourcestimes :: Integral c => c -> (a -> b) -> a -> b Source Semigroup (Either a b) Source Methods(<>) :: Either a b -> Either a b -> Either a b Sourcesconcat :: NonEmpty (Either a b) -> Either a b Sourcestimes :: Integral c => c -> Either a b -> Either a b Source (Semigroup a, Semigroup b) => Semigroup (a, b) Source Methods(<>) :: (a, b) -> (a, b) -> (a, b) Sourcesconcat :: NonEmpty (a, b) -> (a, b) Sourcestimes :: Integral c => c -> (a, b) -> (a, b) Source Semigroup a => Semigroup (Const a b) Source Methods(<>) :: Const a b -> Const a b -> Const a b Sourcesconcat :: NonEmpty (Const a b) -> Const a b Sourcestimes :: Integral c => c -> Const a b -> Const a b Source Semigroup (Proxy k s) Source Methods(<>) :: Proxy k s -> Proxy k s -> Proxy k s Sourcesconcat :: NonEmpty (Proxy k s) -> Proxy k s Sourcestimes :: Integral b => b -> Proxy k s -> Proxy k s Source Ord k => Semigroup (Map k v) Source Methods(<>) :: Map k v -> Map k v -> Map k v Sourcesconcat :: NonEmpty (Map k v) -> Map k v Sourcestimes :: Integral b => b -> Map k v -> Map k v Source (Hashable k, Eq k) => Semigroup (HashMap k a) Source Methods(<>) :: HashMap k a -> HashMap k a -> HashMap k a Sourcesconcat :: NonEmpty (HashMap k a) -> HashMap k a Sourcestimes :: Integral b => b -> HashMap k a -> HashMap k a Source (Semigroup a, Semigroup b, Semigroup c) => Semigroup (a, b, c) Source Methods(<>) :: (a, b, c) -> (a, b, c) -> (a, b, c) Sourcesconcat :: NonEmpty (a, b, c) -> (a, b, c) Sourcestimes :: Integral d => d -> (a, b, c) -> (a, b, c) Source Alternative f => Semigroup (Alt * f a) Source Methods(<>) :: Alt * f a -> Alt * f a -> Alt * f a Sourcesconcat :: NonEmpty (Alt * f a) -> Alt * f a Sourcestimes :: Integral b => b -> Alt * f a -> Alt * f a Source Semigroup a => Semigroup (Tagged k s a) Source Methods(<>) :: Tagged k s a -> Tagged k s a -> Tagged k s a Sourcesconcat :: NonEmpty (Tagged k s a) -> Tagged k s a Sourcestimes :: Integral b => b -> Tagged k s a -> Tagged k s a Source (Semigroup a, Semigroup b, Semigroup c, Semigroup d) => Semigroup (a, b, c, d) Source Methods(<>) :: (a, b, c, d) -> (a, b, c, d) -> (a, b, c, d) Sourcesconcat :: NonEmpty (a, b, c, d) -> (a, b, c, d) Sourcestimes :: Integral e => e -> (a, b, c, d) -> (a, b, c, d) Source (Semigroup a, Semigroup b, Semigroup c, Semigroup d, Semigroup e) => Semigroup (a, b, c, d, e) Source Methods(<>) :: (a, b, c, d, e) -> (a, b, c, d, e) -> (a, b, c, d, e) Sourcesconcat :: NonEmpty (a, b, c, d, e) -> (a, b, c, d, e) Sourcestimes :: Integral f => f -> (a, b, c, d, e) -> (a, b, c, d, e) Source

stimesMonoid :: (Integral b, Monoid a) => b -> a -> a Source

This is a valid definition of `stimes` for a `Monoid`.

Unlike the default definition of `stimes`, it is defined for 0 and so it should be preferred where possible.

stimesIdempotent :: Integral b => b -> a -> a Source

This is a valid definition of `stimes` for an idempotent `Semigroup`.

When `x <> x = x`, this definition should be preferred, because it works in O(1) rather than O(log n).

stimesIdempotentMonoid :: (Integral b, Monoid a) => b -> a -> a Source

This is a valid definition of `stimes` for an idempotent `Monoid`.

When `mappend x x = x`, this definition should be preferred, because it works in O(1) rather than O(log n)

mtimesDefault :: (Integral b, Monoid a) => b -> a -> a Source

Repeat a value `n` times.

`mtimesDefault n a = a <> a <> ... <> a  -- using <> (n-1) times`

Implemented using `stimes` and `mempty`.

This is a suitable definition for an `mtimes` member of `Monoid`.

Since: 0.17

# Semigroups

newtype Min a Source

Constructors

 Min FieldsgetMin :: a

Instances

newtype Max a Source

Constructors

 Max FieldsgetMax :: a

Instances

newtype First a Source

Use `Option (First a)` to get the behavior of `First` from `Data.Monoid`.

Constructors

 First FieldsgetFirst :: a

Instances

newtype Last a Source

Use `Option (Last a)` to get the behavior of `Last` from `Data.Monoid`

Constructors

 Last FieldsgetLast :: a

Instances

newtype WrappedMonoid m Source

Provide a Semigroup for an arbitrary Monoid.

Constructors

 WrapMonoid FieldsunwrapMonoid :: m

Instances

 Source Associated Typestype Rep1 (WrappedMonoid :: * -> *) :: * -> * Methods Bounded a => Bounded (WrappedMonoid a) Source Methods Enum a => Enum (WrappedMonoid a) Source MethodsfromEnum :: WrappedMonoid a -> IntenumFrom :: WrappedMonoid a -> [WrappedMonoid a]enumFromThen :: WrappedMonoid a -> WrappedMonoid a -> [WrappedMonoid a]enumFromTo :: WrappedMonoid a -> WrappedMonoid a -> [WrappedMonoid a]enumFromThenTo :: WrappedMonoid a -> WrappedMonoid a -> WrappedMonoid a -> [WrappedMonoid a] Eq m => Eq (WrappedMonoid m) Source Methods(==) :: WrappedMonoid m -> WrappedMonoid m -> Bool(/=) :: WrappedMonoid m -> WrappedMonoid m -> Bool Data m => Data (WrappedMonoid m) Source Methodsgfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> WrappedMonoid m -> c (WrappedMonoid m)gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (WrappedMonoid m)dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c (WrappedMonoid m))dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (WrappedMonoid m))gmapT :: (forall b. Data b => b -> b) -> WrappedMonoid m -> WrappedMonoid mgmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> WrappedMonoid m -> rgmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> WrappedMonoid m -> rgmapQ :: (forall d. Data d => d -> u) -> WrappedMonoid m -> [u]gmapQi :: Int -> (forall d. Data d => d -> u) -> WrappedMonoid m -> ugmapM :: Monad a => (forall d. Data d => d -> a d) -> WrappedMonoid m -> a (WrappedMonoid m)gmapMp :: MonadPlus a => (forall d. Data d => d -> a d) -> WrappedMonoid m -> a (WrappedMonoid m)gmapMo :: MonadPlus a => (forall d. Data d => d -> a d) -> WrappedMonoid m -> a (WrappedMonoid m) Ord m => Ord (WrappedMonoid m) Source Methods(<) :: WrappedMonoid m -> WrappedMonoid m -> Bool(<=) :: WrappedMonoid m -> WrappedMonoid m -> Bool(>) :: WrappedMonoid m -> WrappedMonoid m -> Bool(>=) :: WrappedMonoid m -> WrappedMonoid m -> Boolmax :: WrappedMonoid m -> WrappedMonoid m -> WrappedMonoid mmin :: WrappedMonoid m -> WrappedMonoid m -> WrappedMonoid m Read m => Read (WrappedMonoid m) Source Methods Show m => Show (WrappedMonoid m) Source MethodsshowsPrec :: Int -> WrappedMonoid m -> ShowSshow :: WrappedMonoid m -> StringshowList :: [WrappedMonoid m] -> ShowS Source Associated Typestype Rep (WrappedMonoid m) :: * -> * Methodsfrom :: WrappedMonoid m -> Rep (WrappedMonoid m) xto :: Rep (WrappedMonoid m) x -> WrappedMonoid m Monoid m => Monoid (WrappedMonoid m) Source Methodsmconcat :: [WrappedMonoid m] -> WrappedMonoid m NFData m => NFData (WrappedMonoid m) Source Methodsrnf :: WrappedMonoid m -> () Source MethodshashWithSalt :: Int -> WrappedMonoid a -> Inthash :: WrappedMonoid a -> Int Monoid m => Semigroup (WrappedMonoid m) Source Methodsstimes :: Integral b => b -> WrappedMonoid m -> WrappedMonoid m Source Source type Rep (WrappedMonoid m) Source

# Re-exported monoids from Data.Monoid

class Monoid a where

The class of monoids (types with an associative binary operation that has an identity). Instances should satisfy the following laws:

• `mappend mempty x = x`
• `mappend x mempty = x`
• `mappend x (mappend y z) = mappend (mappend x y) z`
• `mconcat = `foldr` mappend mempty`

The method names refer to the monoid of lists under concatenation, but there are many other instances.

Some types can be viewed as a monoid in more than one way, e.g. both addition and multiplication on numbers. In such cases we often define `newtype`s and make those instances of `Monoid`, e.g. `Sum` and `Product`.

Minimal complete definition

Methods

mempty :: a

Identity of `mappend`

mappend :: a -> a -> a

An associative operation

mconcat :: [a] -> a

Fold a list using the monoid. For most types, the default definition for `mconcat` will be used, but the function is included in the class definition so that an optimized version can be provided for specific types.

Instances

 Methodsmconcat :: [Ordering] -> Ordering Monoid () Methodsmempty :: ()mappend :: () -> () -> ()mconcat :: [()] -> () Methodsmappend :: All -> All -> Allmconcat :: [All] -> All Methodsmappend :: Any -> Any -> Anymconcat :: [Any] -> Any Methodsmconcat :: [ByteString] -> ByteString Methodsmconcat :: [ByteString] -> ByteString Methodsmconcat :: [Builder] -> Builder Methodsmconcat :: [Builder] -> Builder Methods Methodsmconcat :: [IntSet] -> IntSet Methodsmconcat :: [Builder] -> Builder Monoid [a] Methodsmempty :: [a]mappend :: [a] -> [a] -> [a]mconcat :: [[a]] -> [a] Ord a => Monoid (Max a) Methodsmempty :: Max amappend :: Max a -> Max a -> Max amconcat :: [Max a] -> Max a Ord a => Monoid (Min a) Methodsmempty :: Min amappend :: Min a -> Min a -> Min amconcat :: [Min a] -> Min a Monoid a => Monoid (Dual a) Methodsmempty :: Dual amappend :: Dual a -> Dual a -> Dual amconcat :: [Dual a] -> Dual a Monoid (Endo a) Methodsmempty :: Endo amappend :: Endo a -> Endo a -> Endo amconcat :: [Endo a] -> Endo a Num a => Monoid (Sum a) Methodsmempty :: Sum amappend :: Sum a -> Sum a -> Sum amconcat :: [Sum a] -> Sum a Num a => Monoid (Product a) Methodsmappend :: Product a -> Product a -> Product amconcat :: [Product a] -> Product a Monoid (First a) Methodsmempty :: First amappend :: First a -> First a -> First amconcat :: [First a] -> First a Monoid (Last a) Methodsmempty :: Last amappend :: Last a -> Last a -> Last amconcat :: [Last a] -> Last a Monoid a => Monoid (Maybe a) Lift a semigroup into `Maybe` forming a `Monoid` according to http://en.wikipedia.org/wiki/Monoid: "Any semigroup `S` may be turned into a monoid simply by adjoining an element `e` not in `S` and defining `e*e = e` and `e*s = s = s*e` for all `s ∈ S`." Since there is no "Semigroup" typeclass providing just `mappend`, we use `Monoid` instead. Methodsmempty :: Maybe amappend :: Maybe a -> Maybe a -> Maybe amconcat :: [Maybe a] -> Maybe a Monoid (IntMap a) Methodsmempty :: IntMap amappend :: IntMap a -> IntMap a -> IntMap amconcat :: [IntMap a] -> IntMap a Ord a => Monoid (Set a) Methodsmempty :: Set amappend :: Set a -> Set a -> Set amconcat :: [Set a] -> Set a Monoid (Seq a) Methodsmempty :: Seq amappend :: Seq a -> Seq a -> Seq amconcat :: [Seq a] -> Seq a (Hashable a, Eq a) => Monoid (HashSet a) Methodsmappend :: HashSet a -> HashSet a -> HashSet amconcat :: [HashSet a] -> HashSet a Semigroup a => Monoid (Option a) Methodsmempty :: Option amappend :: Option a -> Option a -> Option amconcat :: [Option a] -> Option a Monoid m => Monoid (WrappedMonoid m) Methodsmconcat :: [WrappedMonoid m] -> WrappedMonoid m (Ord a, Bounded a) => Monoid (Max a) Methodsmempty :: Max amappend :: Max a -> Max a -> Max amconcat :: [Max a] -> Max a (Ord a, Bounded a) => Monoid (Min a) Methodsmempty :: Min amappend :: Min a -> Min a -> Min amconcat :: [Min a] -> Min a Monoid b => Monoid (a -> b) Methodsmempty :: a -> bmappend :: (a -> b) -> (a -> b) -> a -> bmconcat :: [a -> b] -> a -> b (Monoid a, Monoid b) => Monoid (a, b) Methodsmempty :: (a, b)mappend :: (a, b) -> (a, b) -> (a, b)mconcat :: [(a, b)] -> (a, b) Monoid a => Monoid (Const a b) Methodsmempty :: Const a bmappend :: Const a b -> Const a b -> Const a bmconcat :: [Const a b] -> Const a b Monoid (Proxy k s) Methodsmempty :: Proxy k smappend :: Proxy k s -> Proxy k s -> Proxy k smconcat :: [Proxy k s] -> Proxy k s Ord k => Monoid (Map k v) Methodsmempty :: Map k vmappend :: Map k v -> Map k v -> Map k vmconcat :: [Map k v] -> Map k v (Eq k, Hashable k) => Monoid (HashMap k v) Methodsmempty :: HashMap k vmappend :: HashMap k v -> HashMap k v -> HashMap k vmconcat :: [HashMap k v] -> HashMap k v (Monoid a, Monoid b, Monoid c) => Monoid (a, b, c) Methodsmempty :: (a, b, c)mappend :: (a, b, c) -> (a, b, c) -> (a, b, c)mconcat :: [(a, b, c)] -> (a, b, c) Alternative f => Monoid (Alt * f a) Methodsmempty :: Alt * f amappend :: Alt * f a -> Alt * f a -> Alt * f amconcat :: [Alt * f a] -> Alt * f a Monoid a => Monoid (Tagged k s a) Methodsmempty :: Tagged k s amappend :: Tagged k s a -> Tagged k s a -> Tagged k s amconcat :: [Tagged k s a] -> Tagged k s a (Monoid a, Monoid b, Monoid c, Monoid d) => Monoid (a, b, c, d) Methodsmempty :: (a, b, c, d)mappend :: (a, b, c, d) -> (a, b, c, d) -> (a, b, c, d)mconcat :: [(a, b, c, d)] -> (a, b, c, d) (Monoid a, Monoid b, Monoid c, Monoid d, Monoid e) => Monoid (a, b, c, d, e) Methodsmempty :: (a, b, c, d, e)mappend :: (a, b, c, d, e) -> (a, b, c, d, e) -> (a, b, c, d, e)mconcat :: [(a, b, c, d, e)] -> (a, b, c, d, e)

newtype Dual a :: * -> *

The dual of a `Monoid`, obtained by swapping the arguments of `mappend`.

Constructors

 Dual FieldsgetDual :: a

Instances

 Associated Typestype Rep1 (Dual :: * -> *) :: * -> * Methodsfrom1 :: Dual a -> Rep1 Dual ato1 :: Rep1 Dual a -> Dual a Bounded a => Bounded (Dual a) MethodsminBound :: Dual amaxBound :: Dual a Eq a => Eq (Dual a) Methods(==) :: Dual a -> Dual a -> Bool(/=) :: Dual a -> Dual a -> Bool Ord a => Ord (Dual a) Methodscompare :: Dual a -> Dual a -> Ordering(<) :: Dual a -> Dual a -> Bool(<=) :: Dual a -> Dual a -> Bool(>) :: Dual a -> Dual a -> Bool(>=) :: Dual a -> Dual a -> Boolmax :: Dual a -> Dual a -> Dual amin :: Dual a -> Dual a -> Dual a Read a => Read (Dual a) MethodsreadsPrec :: Int -> ReadS (Dual a)readList :: ReadS [Dual a]readPrec :: ReadPrec (Dual a) Show a => Show (Dual a) MethodsshowsPrec :: Int -> Dual a -> ShowSshow :: Dual a -> StringshowList :: [Dual a] -> ShowS Generic (Dual a) Associated Typestype Rep (Dual a) :: * -> * Methodsfrom :: Dual a -> Rep (Dual a) xto :: Rep (Dual a) x -> Dual a Monoid a => Monoid (Dual a) Methodsmempty :: Dual amappend :: Dual a -> Dual a -> Dual amconcat :: [Dual a] -> Dual a NFData a => NFData (Dual a) Since: 1.4.0.0 Methodsrnf :: Dual a -> () Semigroup a => Semigroup (Dual a) Source Methods(<>) :: Dual a -> Dual a -> Dual a Sourcesconcat :: NonEmpty (Dual a) -> Dual a Sourcestimes :: Integral b => b -> Dual a -> Dual a Source type Rep1 Dual = D1 D1Dual (C1 C1_0Dual (S1 S1_0_0Dual Par1)) type Rep (Dual a) = D1 D1Dual (C1 C1_0Dual (S1 S1_0_0Dual (Rec0 a)))

newtype Endo a :: * -> *

The monoid of endomorphisms under composition.

Constructors

 Endo FieldsappEndo :: a -> a

Instances

 Generic (Endo a) Associated Typestype Rep (Endo a) :: * -> * Methodsfrom :: Endo a -> Rep (Endo a) xto :: Rep (Endo a) x -> Endo a Monoid (Endo a) Methodsmempty :: Endo amappend :: Endo a -> Endo a -> Endo amconcat :: [Endo a] -> Endo a Source Methods(<>) :: Endo a -> Endo a -> Endo a Sourcesconcat :: NonEmpty (Endo a) -> Endo a Sourcestimes :: Integral b => b -> Endo a -> Endo a Source type Rep (Endo a) = D1 D1Endo (C1 C1_0Endo (S1 S1_0_0Endo (Rec0 (a -> a))))

newtype All :: *

Boolean monoid under conjunction (`&&`).

Constructors

 All FieldsgetAll :: Bool

Instances

 Methods Methods(==) :: All -> All -> Bool(/=) :: All -> All -> Bool Methodscompare :: All -> All -> Ordering(<) :: All -> All -> Bool(<=) :: All -> All -> Bool(>) :: All -> All -> Bool(>=) :: All -> All -> Boolmax :: All -> All -> Allmin :: All -> All -> All MethodsreadList :: ReadS [All] MethodsshowsPrec :: Int -> All -> ShowSshow :: All -> StringshowList :: [All] -> ShowS Associated Typestype Rep All :: * -> * Methodsfrom :: All -> Rep All xto :: Rep All x -> All Methodsmappend :: All -> All -> Allmconcat :: [All] -> All Since: 1.4.0.0 Methodsrnf :: All -> () Source Methods(<>) :: All -> All -> All Sourcestimes :: Integral b => b -> All -> All Source type Rep All = D1 D1All (C1 C1_0All (S1 S1_0_0All (Rec0 Bool)))

newtype Any :: *

Boolean monoid under disjunction (`||`).

Constructors

 Any FieldsgetAny :: Bool

Instances

 Methods Methods(==) :: Any -> Any -> Bool(/=) :: Any -> Any -> Bool Methodscompare :: Any -> Any -> Ordering(<) :: Any -> Any -> Bool(<=) :: Any -> Any -> Bool(>) :: Any -> Any -> Bool(>=) :: Any -> Any -> Boolmax :: Any -> Any -> Anymin :: Any -> Any -> Any MethodsreadList :: ReadS [Any] MethodsshowsPrec :: Int -> Any -> ShowSshow :: Any -> StringshowList :: [Any] -> ShowS Associated Typestype Rep Any :: * -> * Methodsfrom :: Any -> Rep Any xto :: Rep Any x -> Any Methodsmappend :: Any -> Any -> Anymconcat :: [Any] -> Any Since: 1.4.0.0 Methodsrnf :: Any -> () Source Methods(<>) :: Any -> Any -> Any Sourcestimes :: Integral b => b -> Any -> Any Source type Rep Any = D1 D1Any (C1 C1_0Any (S1 S1_0_0Any (Rec0 Bool)))

newtype Sum a :: * -> *

Constructors

 Sum FieldsgetSum :: a

Instances

 Associated Typestype Rep1 (Sum :: * -> *) :: * -> * Methodsfrom1 :: Sum a -> Rep1 Sum ato1 :: Rep1 Sum a -> Sum a Bounded a => Bounded (Sum a) MethodsminBound :: Sum amaxBound :: Sum a Eq a => Eq (Sum a) Methods(==) :: Sum a -> Sum a -> Bool(/=) :: Sum a -> Sum a -> Bool Num a => Num (Sum a) Methods(+) :: Sum a -> Sum a -> Sum a(-) :: Sum a -> Sum a -> Sum a(*) :: Sum a -> Sum a -> Sum anegate :: Sum a -> Sum aabs :: Sum a -> Sum asignum :: Sum a -> Sum a Ord a => Ord (Sum a) Methodscompare :: Sum a -> Sum a -> Ordering(<) :: Sum a -> Sum a -> Bool(<=) :: Sum a -> Sum a -> Bool(>) :: Sum a -> Sum a -> Bool(>=) :: Sum a -> Sum a -> Boolmax :: Sum a -> Sum a -> Sum amin :: Sum a -> Sum a -> Sum a Read a => Read (Sum a) MethodsreadsPrec :: Int -> ReadS (Sum a)readList :: ReadS [Sum a]readPrec :: ReadPrec (Sum a) Show a => Show (Sum a) MethodsshowsPrec :: Int -> Sum a -> ShowSshow :: Sum a -> StringshowList :: [Sum a] -> ShowS Generic (Sum a) Associated Typestype Rep (Sum a) :: * -> * Methodsfrom :: Sum a -> Rep (Sum a) xto :: Rep (Sum a) x -> Sum a Num a => Monoid (Sum a) Methodsmempty :: Sum amappend :: Sum a -> Sum a -> Sum amconcat :: [Sum a] -> Sum a NFData a => NFData (Sum a) Since: 1.4.0.0 Methodsrnf :: Sum a -> () Num a => Semigroup (Sum a) Source Methods(<>) :: Sum a -> Sum a -> Sum a Sourcesconcat :: NonEmpty (Sum a) -> Sum a Sourcestimes :: Integral b => b -> Sum a -> Sum a Source type Rep1 Sum = D1 D1Sum (C1 C1_0Sum (S1 S1_0_0Sum Par1)) type Rep (Sum a) = D1 D1Sum (C1 C1_0Sum (S1 S1_0_0Sum (Rec0 a)))

newtype Product a :: * -> *

Monoid under multiplication.

Constructors

 Product FieldsgetProduct :: a

Instances

 Associated Typestype Rep1 (Product :: * -> *) :: * -> * Methodsfrom1 :: Product a -> Rep1 Product ato1 :: Rep1 Product a -> Product a Bounded a => Bounded (Product a) Methods Eq a => Eq (Product a) Methods(==) :: Product a -> Product a -> Bool(/=) :: Product a -> Product a -> Bool Num a => Num (Product a) Methods(+) :: Product a -> Product a -> Product a(-) :: Product a -> Product a -> Product a(*) :: Product a -> Product a -> Product anegate :: Product a -> Product aabs :: Product a -> Product asignum :: Product a -> Product a Ord a => Ord (Product a) Methodscompare :: Product a -> Product a -> Ordering(<) :: Product a -> Product a -> Bool(<=) :: Product a -> Product a -> Bool(>) :: Product a -> Product a -> Bool(>=) :: Product a -> Product a -> Boolmax :: Product a -> Product a -> Product amin :: Product a -> Product a -> Product a Read a => Read (Product a) MethodsreadsPrec :: Int -> ReadS (Product a)readList :: ReadS [Product a] Show a => Show (Product a) MethodsshowsPrec :: Int -> Product a -> ShowSshow :: Product a -> StringshowList :: [Product a] -> ShowS Associated Typestype Rep (Product a) :: * -> * Methodsfrom :: Product a -> Rep (Product a) xto :: Rep (Product a) x -> Product a Num a => Monoid (Product a) Methodsmappend :: Product a -> Product a -> Product amconcat :: [Product a] -> Product a NFData a => NFData (Product a) Since: 1.4.0.0 Methodsrnf :: Product a -> () Num a => Semigroup (Product a) Source Methods(<>) :: Product a -> Product a -> Product a Sourcesconcat :: NonEmpty (Product a) -> Product a Sourcestimes :: Integral b => b -> Product a -> Product a Source type Rep1 Product = D1 D1Product (C1 C1_0Product (S1 S1_0_0Product Par1)) type Rep (Product a) = D1 D1Product (C1 C1_0Product (S1 S1_0_0Product (Rec0 a)))

# A better monoid for Maybe

newtype Option a Source

`Option` is effectively `Maybe` with a better instance of `Monoid`, built off of an underlying `Semigroup` instead of an underlying `Monoid`.

Ideally, this type would not exist at all and we would just fix the `Monoid` instance of `Maybe`

Constructors

 Option FieldsgetOption :: Maybe a

Instances

option :: b -> (a -> b) -> Option a -> b Source

Fold an `Option` case-wise, just like `maybe`.

# Difference lists of a semigroup

diff :: Semigroup m => m -> Endo m Source

This lets you use a difference list of a `Semigroup` as a `Monoid`.

cycle1 :: Semigroup m => m -> m Source

A generalization of `cycle` to an arbitrary `Semigroup`. May fail to terminate for some values in some semigroups.

# ArgMin, ArgMax

data Arg a b Source

`Arg` isn't itself a `Semigroup` in its own right, but it can be placed inside `Min` and `Max` to compute an arg min or arg max.

Constructors

 Arg a b

Instances