mirror of
https://github.com/idris-lang/Idris2.git
synced 2024-11-28 11:05:17 +03:00
[prelude] Use foldl
for sum and product
To make them tail recursive. Fixes #132.
This commit is contained in:
parent
1212e56903
commit
728149f2d1
@ -630,12 +630,12 @@ all p = foldl (\x,y => x && p y) True
|
||||
||| Add together all the elements of a structure.
|
||||
public export
|
||||
sum : (Foldable t, Num a) => t a -> a
|
||||
sum = foldr (+) 0
|
||||
sum = foldl (+) 0
|
||||
|
||||
||| Multiply together all elements of a structure.
|
||||
public export
|
||||
product : (Foldable t, Num a) => t a -> a
|
||||
product = foldr (*) 1
|
||||
product = foldl (*) 1
|
||||
|
||||
||| Map each element of a structure to a computation, evaluate those
|
||||
||| computations and discard the results.
|
||||
|
Loading…
Reference in New Issue
Block a user