||||||||||||||||||||||||||||||||||||||||||||||||||| || Part 1 ||||||||||||||||||||||||||||||||||||||||||||||||||| ||||||||||||||||| || Definitions cube x = x*x*x my_map f [] = [] my_map f (x:xs) = f x : my_map f xs my_append [] ys = ys my_append (x:xs) ys = x : my_append xs ys my_map2 f [] [] = [] my_map2 f (a:as) (b:bs) = f a b : my_map2 f as bs rev f x y = f y x alligator x y = 3+y ||||||||||||||||| || Results || cube 3 => 27 || cube :: => num->num || my_map :: => (*->**)->[*]->[**] || my_map cube :: => [num]->[num] || my_map cube [1..] => [3 8 ...] || my_append :: => [*]->[*]->[*] || my_map2 :: => (*->**->***)->[*]->[**]->[***] || my_map2 alligator :: => [*]->[num]->[num] || my_map2 (rev alligator) :: => [num]->[*]->[num] || alligator (1/0) (6/2) => 6.0 || alligator (6/2) (1/0) => program error || alligator :: => *->num->num || (rev alligator) 10 20 => 13 || rev :: => (*->**->***)->**->*->*** || rev my_map2:: => [*]->(*->**->***)->[**]->[***] ||||||||||||||||||||||||||||||||||||||||||||||||||| || Part II ||||||||||||||||||||||||||||||||||||||||||||||||||| ||||||||||||||||| || Problem 2.1 || calculates midpoint of two points midpoint (a,b) (c,d) = ((a+c)/2, (b+d)/2) ||||||||||||||||| || Problem 2.2 || helper for no_duplicates remove_element [] x = [] remove_element (x:xs) x = remove_element xs x remove_element (y:xs) x = y : remove_element xs x || removes duplicate elements from a list no_duplicates [] = [] no_duplicates (x:xs) = x : no_duplicates (remove_element xs x) ||||||||||||||||| || Problem 2.3 next_pascal :: [num]->[num] || next_pascal works like this: || next_pascal [a, b, c, ..., n] <==> || || [0, a, b, c, ..., n] || + [a, b, c, ..., n, 0] || ---------------------- || [a+0, a+b, b+c, ..., n+0] next_pascal xs = my_map2 (+) (xs ++ [0]) (0 : xs) pascal = [1] : map next_pascal pascal