{- Exercise 6.1 -} data Time = Time Integer Integer Integer deriving Show -- Exercise 6.1.1 hours :: Time -> Integer hours = undefined minutes :: Time -> Integer minutes = undefined seconds :: Time -> Integer seconds = undefined -- Exercise 6.1.2 well_formed :: Time -> Bool well_formed = undefined -- Exercise 6.1.3 pretty :: Time -> String pretty = undefined -- Exercise 6.1.4 tick :: Time -> Time tick = undefined {- Exercise 6.2 -} -- Exercise 6.2.1 -- Add your datatype definition here data Region -- innsbruck, tyrol and austria are so called constants -- to define a constant in Haskell you simple define a function that takes no parameters innsbruck :: Region innsbruck = undefined tyrol :: Region tyrol = undefined austria :: Region austria = undefined -- Exercise 6.2.1 name :: Region -> String name _ = undefined population :: Region -> Integer population _ = undefined typeOfRegion :: Region -> String typeOfRegion = undefined -- Exercise 6.2.3 info :: Region -> String info r = undefined {- Exercise 6.3 -} -- Exercise 6.3.1 ev :: String -> String ev s = undefined od :: String -> String od s = undefined merge :: String -> String -> String merge s t = undefined -- Exercise 6.3.2 lshift :: String -> String lshift s = undefined sand :: String -> String -> String sand s = undefined -- below some functions that allow to test correctness. -- they are there for your convenience. note that these are tests: -- if a test fails you can conclude something is wrong -- but if a test succeeds you cannot conclude that everything is right, -- only that some things (those tested) are -- test of all functions in 6.3 test63 = test631 && test632 && testMatch -- test of functions in 6.3.1 test631 = testEvOdMerge "" && testEvOdMerge "ababacda" testEvOdMerge s = merge (ev s) (od s) == s test631error = testEvOdMerge "a" -- test of functions in 6.3.2 test632 = lshift "ababacda" == "babacdaF" && sand "aTbTTcF" "xTbcTcT" == "FTFFTFF" testMatch = match "a" "ababacda" == "TFTFTFFT" && match "ab" "ababacda" == "TFTFFFFF" && match "abab" "ababacda" == "TFFFFFFF" && match "c" "ababacda" == "FFFFFTFF" && match "e" "ababacda" == "FFFFFFFF" -- function that indicates at which positions -- the first string occurs in the second string -- T if it occurs there, F if it does not occur; see testMatch for examples match :: String -> String -> String match [c] [d] = if c == d then "T" else "F" match [c] rs = merge (match [c] (ev rs)) (match [c] (od rs)) match _ [d] = "F" match pq rs = merge (sand (match (ev pq) (ev rs)) (match (od pq) (od rs))) (sand (lshift (match (od pq) (ev rs))) (match (ev pq) (od rs))) -- this match function makes use of all functions in 6.3 -- this function only works for strings that have a power of 2 (1,2,4,..) as length -- (you do not need to understand how and why the function works)