sum package:base

The sum function computes the sum of the numbers of a structure.

Examples

Basic usage:
>>> sum []
0
>>> sum [42]
42
>>> sum [1..10]
55
>>> sum [4.1, 2.0, 1.7]
7.8
>>> sum [1..]
* Hangs forever *
The sum function computes the sum of a finite list of numbers.
>>> sum []
0

>>> sum [42]
42

>>> sum [1..10]
55

>>> sum [4.1, 2.0, 1.7]
7.8

>>> sum [1..]
* Hangs forever *
Sums, lifted to functors.
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}
An unboxed sum of the given reps
The sum of a collection of actions using (<|>), generalizing concat. msum is just like asum, but specialised to MonadPlus.

Examples

Basic usage, using the MonadPlus instance for Maybe:
>>> msum [Just "Hello", Nothing, Just "World"]
Just "Hello"
The sum of a collection of actions using (<|>), generalizing concat. asum is just like msum, but generalised to Alternative.

Examples

Basic usage:
>>> asum [Just "Hello", Nothing, Just "World"]
Just "Hello"
The sum of a collection of actions, generalizing biconcat.

Examples

Basic usage:
>>> biasum (Nothing, Nothing)
Nothing
>>> biasum (Nothing, Just 42)
Just 42
>>> biasum (Just 18, Nothing)
Just 18
>>> biasum (Just 18, Just 42)
Just 18
Alias for biasum.
The bisum function computes the sum of the numbers of a structure.

Examples

Basic usage:
>>> bisum (42, 17)
59
>>> bisum (Right 42)
42
>>> bisum (BiList [13, 29, 4] [18, 1, 7])
72
>>> bisum (BiList [13, 29, 4] [])
46
>>> bisum (BiList [] [])
0