MATH 1120 Quiz: MATH 1120 Cornell WARMUP2018 Quiz4 24Solutions

34 views10 pages
31 Jan 2019
Department
Course
Professor

Document Summary

You have one and a half hours for the exam. This is a closed-book examination; you may not use outside materials. 100: types, polymorphism [14 pts] (parts a b) (a) [9 pts] For each of the 3 functions below, pick an appropriate type for it from the list below: fun f x y = (y, x) The type is: fun f (x, y) z = z y. The type is: fun f x y = fn y => (y, x) That is, odd elements have some type "a, and even elements have some type "b. 2: pattern matching [18 pts] (parts a b) (a) [8 pts] the following datatype describes syntax trees for arithmetic expressions: datatype expr = const of int. If list b is too short, excess elements are appended. For example: zip([1, 2, 3, 4], [11, 12, 13]) = [1, 11, 12, 2, 13, 3, 4] fun zip(a: int list, b: int list): int list =