{- Exercise 2.2 -} -- values from the exercise sheet baseAttack :: Integer baseAttack = 3 baseDefense :: Integer baseDefense = 4 -- intermediate functions, identified by your functional decomposition -- change names, types and definitions totalAttack :: Integer -> Integer totalAttack x = error "write the defining equation here" -- main function: calculateDamage -- calculateDamage :: uncomment this line and write the correct type calculateDamage = error "write the defining equation here" {- Exercise 2.3 -} -- 1.) square :: Integer -> Integer square n = error "square not yet defined" -- 2.) -- 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 -} -- the following functions can be run in ghci to test your implementations test_square = if square 3 == 3^2 then True else error "test on square failed" -- 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