Hoogle Search
Within LTS Haskell 24.3 (ghc-9.10.2)
Note that Stackage only displays results for the latest LTS and Nightly snapshot. Learn more.
-
numeric-prelude NumericPrelude 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.
-
numeric-prelude NumericPrelude.Numeric 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 :: (Additive a, Foldable f) => f a -> anumhask NumHask Compute the sum of a Foldable.
>>> sum [0..10] 55
sum :: (Additive a, Foldable f) => f a -> anumhask NumHask.Algebra.Additive Compute the sum of a Foldable.
>>> sum [0..10] 55
sum :: (Num a, ListLike full a) => full -> aListLike Data.ListLike The sum of the list
sum :: (Num a, ListLike full a) => full -> aListLike Data.ListLike.Utils The sum of the list
sum :: (Foldable f, Num a) => f a -> abasic-prelude BasicPrelude Compute the sum of a finite list of numbers.
sum :: (Foldable t, Num a) => t a -> aghc-lib-parser GHC.Prelude.Basic 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 *
sum :: (RealFloat a, Foldable f) => f (Log a) -> Log alog-domain Numeric.Log Efficiently and accurately compute the sum of a set of log-domain numbers While folding with (+) accomplishes the same end, it requires an additional n-2 logarithms to sum n terms. In addition, here we introduce fewer opportunities for round-off error. While for small quantities the naive sum accumulates error,
>>> let xs = Prelude.replicate 40000 (Exp 1e-4) :: [Log Float] >>> Prelude.sum xs ~= 4.00e4 True
This sum gives a more accurate result,>>> Numeric.Log.sum xs ~= 4.00e4 True
NB: This does require two passes over the data.-
prelude-compat Data.List2010 No documentation available.