homework examples
This commit is contained in:
parent
566bdfc66c
commit
8f7fac09b9
1 changed files with 14 additions and 0 deletions
14
Lecture 02/scratch/Scratch.hs
Normal file
14
Lecture 02/scratch/Scratch.hs
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
module Scratch where
|
||||||
|
|
||||||
|
neg :: Integer -> Integer
|
||||||
|
neg x = (-x)
|
||||||
|
|
||||||
|
sumTo20 :: [Integer] -> Integer
|
||||||
|
sumTo20 nums = sumTo20Acc 0 nums
|
||||||
|
|
||||||
|
sumTo20Acc :: Integer -> [Integer] -> Integer
|
||||||
|
sumTo20Acc acc [] = acc
|
||||||
|
sumTo20Acc acc (x:xs)
|
||||||
|
| acc >= 20 = acc
|
||||||
|
| otherwise = sumTo20Acc (acc + x) xs
|
||||||
|
|
Loading…
Reference in a new issue