{- Solution to Exercise Sheet 2 -} {- Exercise 2.2 -} -- values from the exercise sheet baseAttack :: Integer baseAttack = 4 baseDefense :: Integer baseDefense = 3 -- intermediate functions, identified by your functional decomposition -- change names, types and definitions first_intermediate_fun :: Integer -> Integer -> Integer -> Integer first_intermediate_fun x y z = error "not yet specified" -- main function: calculateDamage -- calculateDamage :: uncomment this line and write the correct type calculateDamage = error "write the defining equation here" {- Exercise 2.3 -} square :: Integer -> Integer square n = error "square not yet defined" -- invoke test_square in ghci test_square = if square 3 == 3^2 then True else error "test on square failed" -- factorial from the lecture fact :: Integer -> Integer fact n = if n > 0 then n * fact (n - 1) else 1 binom_fd :: Integer -> Integer -> Integer binom_fd n k = error "binom_fd not yet defined" binom_dc :: Integer -> Integer -> Integer binom_dc n k = error "binom_dc not yet defined" -- tests for binomials test_binom_fd = if binom_fd 3 2 == 3 then True else error "test on binom_fd failed" test_binom_dc = if binom_dc 3 2 == 3 then True else error "test on binom_dc failed" -- a test for all parts of exercise 2.3: invoke test_ex_2_3 in ghci test_ex_2_3 = test_square && test_binom_fd && test_binom_dc