sum package:base-compat

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 *
Monoid under addition.
>>> getSum (Sum 1 <> Sum 2 <> mempty)
3
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"