mirror of
https://github.com/thma/WhyHaskellMatters.git
synced 2024-09-11 13:46:11 +03:00
some more ideas
This commit is contained in:
parent
4a50430249
commit
01cb17b1b7
@ -38,4 +38,19 @@ factorial n =
|
||||
-- definition of factorial using pattern matching
|
||||
fac :: Natural -> Natural
|
||||
fac 0 = 1
|
||||
fac n = n * fac (n - 1)
|
||||
fac n = n * fac (n - 1)
|
||||
|
||||
someNumbers :: [Integer]
|
||||
someNumbers = [49,64,97,54,19,90,934,22,215,6,68,325,720,8082,1,33,31]
|
||||
|
||||
sumUp :: [Integer] -> Integer
|
||||
sumUp [] = 0
|
||||
sumUp (n:rest) = n + sumUp rest
|
||||
|
||||
prod :: [Integer] -> Integer
|
||||
prod [] = 1
|
||||
prod (n:rest) = n * prod rest
|
||||
|
||||
betterSum :: [Integer] -> Integer
|
||||
betterSum = foldr (+) 0
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user