This repository has been archived on 2024-12-15. You can view files and clone it, but cannot push or open issues or pull requests.
CIS194/Lecture 02/scratch/Scratch.hs

15 lines
282 B
Haskell
Raw Normal View History

2016-09-24 21:09:51 +00:00
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