sum

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 *
Get the sum of all values in the stream. Subject to fusion
Compute the sum of the elements of a Producer
Computes the sum of all elements
The sum of elements in the original Sample. This is the sample's first simple power.
Stricter version of sum.
>>> sum [1..10]
55
Fold a Stream of numbers into their sum with the return value
mapped S.sum :: Stream (Stream (Of Int)) m r -> Stream (Of Int) m r
>>> S.sum $ each [1..10]
55 :> ()
>>> (n :> rest)  <- S.sum $ S.splitAt 3 $ each [1..10]

>>> System.IO.print n
6

>>> (m :> rest') <- S.sum $ S.splitAt 3 rest

>>> System.IO.print m
15

>>> S.print rest'
7
8
9
10
The sum function computes the sum of the numbers of a structure.
O(n) Compute the sum of the elements

Examples

>>> import qualified Data.Vector as V

>>> V.sum $ V.fromList [300,20,1 :: Int]
321

>>> V.sum (V.empty :: V.Vector Int)
0
O(n) Compute the sum of the elements

Examples

>>> import qualified Data.Vector as V

>>> V.sum $ V.fromList [300,20,1 :: Int]
321

>>> V.sum (V.empty :: V.Vector Int)
0
O(n) Compute the sum of the elements

Examples

>>> import qualified Data.Vector.Storable as VS

>>> VS.sum $ VS.fromList [300,20,1 :: Int]
321

>>> VS.sum (VS.empty :: VS.Vector Int)
0
O(n) Compute the sum of the elements

Examples

>>> import qualified Data.Vector.Unboxed as VU

>>> VU.sum $ VU.fromList [300,20,1 :: Int]
321

>>> VU.sum (VU.empty :: VU.Vector Int)
0
Synonym for osum
sum does not need a zero for initialization
Sum of values
Sum of values
The sum of the list
Sum up all elements of a list. An empty list yields zero. This function is inappropriate for number types like Peano. Maybe we should make sum a method of Additive. This would also make lengthLeft and lengthRight superfluous.
Sum a collection of values. Example: foo = sum kbn [1,2,3]
Determine the sum of all elements of a stream of numbers. Returns 0 when the stream is empty. Note that this is not numerically stable for floating point numbers.
sum = Stream.fold Fold.sum