From 431528255ca69e5b9f1435f80db758a9c62a9bd3 Mon Sep 17 00:00:00 2001 From: AJ Date: Wed, 3 Feb 2016 10:31:05 -0800 Subject: [PATCH] day 6: haskell intro --- recursion.hs | 11 +++++++++++ syntax.hs | 5 +++++ 2 files changed, 16 insertions(+) create mode 100644 recursion.hs create mode 100644 syntax.hs diff --git a/recursion.hs b/recursion.hs new file mode 100644 index 0000000..4a6fd2d --- /dev/null +++ b/recursion.hs @@ -0,0 +1,11 @@ +sumsq 0 = 0 +sumsq n = n ^ 2 + sumsq (n - 1) + +sumLinear [] = 0 +sumLinear (x:xs) = x + (sumLinear xs) + +sumTail lst = sumTailHelper lst 0 +sumTailHelper [] total = total +sumTailHelper (x:xs) total = sumTailHelper xs (total + x) + +sumFoldr lst = foldr (+) 0 lst \ No newline at end of file diff --git a/syntax.hs b/syntax.hs new file mode 100644 index 0000000..47cf042 --- /dev/null +++ b/syntax.hs @@ -0,0 +1,5 @@ + +cmp a b + | a < b = -1 + | a > b = 1 + | otherwise = 0 \ No newline at end of file