{- Exercise 4.1 -} -- 1) using if-then-else, and, or, not boolFunIf :: Bool -> Bool -> Bool -> Bool boolFunIf = undefined -- 2) using if-then-else, and, or, not boolFunAon :: Bool -> Bool -> Bool -> Bool boolFunAon = undefined -- 3) using pattern matching boolFunPm :: Bool -> Bool -> Bool -> Bool boolFunPm = undefined {- Exercise 4.2 -} -- 4.2.1 -- define this datatype and the functions below data Party = CHANGE_ME mps :: Party -> Party -> Integer mps = undefined coalition :: Party -> Party -> Bool coalition = undefined -- 4.2.2 -- define this datatype and the functions below data Season = CHANGE_ME_TOO -- define the function and write the type signature -- pattern matching -- daysInSeasonPM :: daysInSeasonPM = undefined -- if-then-else -- daysInSeasonITE :: daysInSeasonITE = undefined {- Exercise 4.3 -} -- 4.3.1 foo :: a -> a -> a foo = undefined bar :: a -> a -> a bar = undefined -- 4.3.2 -- ADD ANSWER TO 4.3.2 HERE -- {- Exercise 4.4 -} isDivisible :: Integer -> Integer -> Bool isDivisible x y = div x y * y == x g :: Integer -> Integer g x = error "TODO g not implemented" c :: Integer -> Integer c x = error "TODO c not implemented" {- Tests -} {- You don't have to understand the Haskell-code in the tests, but you can just invoke them after having implemented some exercises -} testData :: [((Bool, Bool, Bool), Bool)] testData = [ ((False, False, False), False) , ((False, False, True) , False) , ((False, True, False) , True) , ((False, True, True) , True) , ((True, False, False) , False) , ((True, False, True) , True) , ((True, True, False) , True) , ((True, True, True) , False) ] testBool :: (Bool -> Bool -> Bool -> Bool) -> Bool testBool f = all (\((x,y,z),s) -> f x y z == s) testData testBoolIf, testBoolAon, testBoolPm :: Bool testBoolIf = testBool boolFunIf || error "test for boolFunIf failed" testBoolAon = testBool boolFunAon || error "test for boolFunIf failed" testBoolPm = testBool boolFunPm || error "test for boolFunIf failed" test_g = g 25 == 76 && g 2 == 1 || error "test_g failed" test_c = c 1 == 0 && c 8 == 3 && c 103 == 87 || error "test_c failed" -- test for all exercises test_all = test_c && test_g && testBoolIf && testBoolAon && testBoolPm