{- 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 -- define the function and write the type signature -- threeEqual :: threeEqual x y z = undefined -- 4.3.2 foo :: a -> a -> a foo = undefined bar :: a -> a -> a bar = undefined {- 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) ] uncurry3 :: (a -> b -> c -> d) -> ((a, b, c) -> d) uncurry3 f (x, y, z) = f x y z testBool :: (Bool -> Bool -> Bool -> Bool) -> Bool testBool f = all (\t -> (snd t ==) . uncurry3 f $ fst t) 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" testThreeEqual :: Bool testThreeEqual = threeEqual 'a' 'a' 'a' && not (threeEqual True False True) && not (threeEqual 2 1 1) && not (threeEqual 1 1 2) && not (threeEqual 1 2 2) && not (threeEqual 2 1 2) && not (threeEqual 2 2 1) && not (threeEqual "a" "b" "c") || error "test for threeEqual failed" testFooBar = foo 1 2 /= bar 1 2 && foo True False /= bar True False testAll :: Bool testAll = testBoolIf && testBoolAon && testBoolPm && testThreeEqual && testFooBar