Sum -is:module

Lifted sum of functors.

Examples

>>> fmap (+1) (InL (Just 1))  :: Sum Maybe [] Int
InL (Just 2)
>>> fmap (+1) (InR [1, 2, 3]) :: Sum Maybe [] Int
InR [2,3,4]
Monoid under addition.
Sum a <> Sum b = Sum (a + b)

Examples

>>> Sum 1 <> Sum 2 <> mempty
Sum {getSum = 3}
>>> mconcat [ Sum n | n <- [3 .. 9]]
Sum {getSum = 42}
Sum (Left q) = 2*q
Sum (Right q) = 2*q+1
Last two are the locations of the '|' before and after the payload
Monoid under addition.
>>> getSum (Sum 1 <> Sum 2 <> mempty)
3
Monoid under group addition. Alternative to the Sum in Data.Monoid, which uses Num instead of AdditiveGroup.
Lifted sum of functors.
Monoid under addition.
>>> getSum (Sum 1 <> Sum 2 <> mempty)
3
Sum a Nat-list.

Example

>>> :kind! Eval (Sum '[1,2,3])
Eval (Sum '[1,2,3]) :: Natural
= 6
Monoid under addition.
>>> getSum (Sum 1 <> Sum 2 <> mempty)
3
A wrapper for an Additive which distinguishes the additive structure
Last two are the locations of the '|' before and after the payload
Sum of field values to be used in an aggregate operation.
Lifted sum of functors.
SUM Corresponds to the `SUM` function.
Sum of WeightedTerm