CPSC 349 Exercise 3 SolutionI.gcd (9, 24) = gcd (24, 9) = gcd (9, 6) = gcd (6, 3) = gcd (3, 0) = 3II.
Any even-valued parameter will cause the if test to succeed, and the function will terminate.
orderit [4, 3, 6, 1] = [6] ++ (orderit [4, 3, 1]) = [6] ++ ([4] ++ (orderit [3, 1])) = [6] ++ ([4] ++ ([3] ++ (orderit [1]))) = [6] ++ ([4] ++ ([3] ++ ([1] ++ (orderit [])))) = [6] ++ ([4] ++ ([3] ++ ([1] ++[]))) = [6, 4, 3, 1](b) Since 'c' > 'b' > 'M', then "cat" > "bet" > "Mut" and so by lines {5} and {6}, the maximum element of the list each time through is "cat" followed by "bet" followed by "Mut". Therefore: orderit ["bet", "cat", "Mut"] = ["cat", "bet", "Mut"](c) We note that the elements of the list 3, "dog" and 2.5 are not of a common type, and cannot be promoted to any one common type, therefore this violates line {1} in the listing for orderit which claims that "orderit :: Ord a => [a] -> [a]" takes a list containing variables of a common type a. We can find no such a that satisfies the given expression. IV. doit = (\x -> (\y -> (x ^ y)))V.
![]() (b) x: bound everywhere y: bound everywhere z: free everywhere |