From 8f7fac09b94fac11f58f8ca992c452754cdca1d2 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Sat, 24 Sep 2016 23:09:51 +0200 Subject: [PATCH] homework examples --- Lecture 02/scratch/Scratch.hs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Lecture 02/scratch/Scratch.hs diff --git a/Lecture 02/scratch/Scratch.hs b/Lecture 02/scratch/Scratch.hs new file mode 100644 index 0000000..ffaa789 --- /dev/null +++ b/Lecture 02/scratch/Scratch.hs @@ -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 +