:: Num a => [a] -> a -package:ginger

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 *
The product function computes the product of a finite list of numbers.
>>> product []
1

>>> product [42]
42

>>> product [1..10]
3628800

>>> product [4.1, 2.0, 1.7]
13.939999999999998

>>> product [1..]
* Hangs forever *
A strict version of sum. Unlike sum this function is always strict in the Num argument, whereas the standard version is only strict if the optimiser kicks in.
sum' [1, 2, 3] == 6
A strict version of product.
product' [1, 2, 4] == 8
Strict version of sum that doesn’t leak space
tail resursive
lazy recursion.
With argument order flipped
Lazy with argument order flipped.
Co-routine style
Co-routine, go style
Co-routine, case-style
Auxillary style.
foldr style
cata style
sum
Polymorphic sum
Lambda-style sum
GHC-style foldr method.
Warning: This is a partial function, it throws an error on empty lists. Use pattern matching, uncons or listToMaybe instead. Consider refactoring to use Data.List.NonEmpty.
Extract the last element of a list, which must be finite and non-empty. WARNING: This function is partial. Consider using unsnoc instead.

Examples

>>> last [1, 2, 3]
3
>>> last [1..]
* Hangs forever *
>>> last []
*** Exception: Prelude.last: empty list