MATH 1120 Quiz: MATH 1120 Cornell WARMUP2018 Quiz4 26Solutions

45 views13 pages
31 Jan 2019
Department
Course
Professor

Document Summary

You have one and a half hours to do this exam. All programs in this exam must be written in sml. 1: (type inference in ml, 25 points) (a) (5 points) consider the ml function shown below. fun foldr f a l = case l of nil => a. | (h::t) => f(h,foldr f a t: (3 points) write down a set of type equations for this function. Type variables: f:t1 a:t2 l:t3 return type of foldr: t4} Solve to get t1 = t3" x t4 -> t4 t2 = t4 t3 = t3" list t5 = t4. So type of foldr is ((t3" x t4)-> t4) -> t4 -> (t3" list) -> t4. For each equation, write two or three words to explain where the equation comes from. Type variables: f:t1 z:t2 return type of scanr: t3 e: t4 l:t5 foldr has type (axb -> b) -> b ->(a list) -> b.