From 22debc12d715b6df30ac32490b94c0229b26472a Mon Sep 17 00:00:00 2001 From: Albert Stein Date: Mon, 17 Oct 2016 15:00:19 +0000 Subject: [PATCH] Lesson samples --- Lecture 03/Scratch/Scratch.hs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Lecture 03/Scratch/Scratch.hs diff --git a/Lecture 03/Scratch/Scratch.hs b/Lecture 03/Scratch/Scratch.hs new file mode 100644 index 0000000..713a407 --- /dev/null +++ b/Lecture 03/Scratch/Scratch.hs @@ -0,0 +1,24 @@ +module Scratch where + +mapInteger :: (Integer -> Integer) -> [Integer] -> [Integer] +mapInteger _ [] = [] +mapInteger f (x:xs) = f x : mapInteger f xs + +plus1 :: Integer -> Integer +plus1 x = x + 1 + +filterInteger :: (Integer -> Bool) -> [Integer] -> [Integer] +filterInteger _ [] = [] +filterInteger f (x:xs) + | f x == True = x : filterInteger f xs + | otherwise = filterInteger f xs + +greaterThanTwo :: Integer -> Bool +greaterThanTwo x = x > 2 + +data Tree = Leaf Char + | Node Tree Int Tree + deriving Show + +tree :: Tree +tree = Node (Leaf 'x') 1 (Node (Leaf 'y') 2 (Leaf 'z'))