The superscript "(d)" stands for "difficult". Exercises similar to those marked with "(d)" might appear in candidacy exams, but not in the standard exams of CSE 428.
fn f => fn g => fn x => f (g x);
fn f => fn (x,y) => f x;
fn x => fn f => (x, (f x));
('a -> 'b) -> ('c -> 'a) -> 'c -> 'b
('a -> 'b) -> 'a * 'c -> 'b
'a -> ('a -> 'b) -> 'a * 'b
fun f g x = g (g x);
fun f g x = (g g) x;
fun f g x y = g(y,x);
fun f g x = if x then true else g (f g true) x;
fun f g x y = if x then y else g (x + y);
('a -> 'a) -> 'a -> 'a
('a * 'b -> 'c) -> 'b -> 'a -> 'c
(bool -> bool -> bool) -> bool -> bool
fun f nil = nil | f (x :: l) = (x :: nil) :: (f l);
fun f nil = nil | f (g :: l) = g (f l);
fun f nil = nil | f (nil :: l) = nil :: nil | f l = l;
fun f nil = nil | f (nil :: l) = l :: nil | f l = l;
fun f nil k = nil | f l nil = nil | f (x :: l) (y :: k) = (x,y) :: (f l k);
'a list -> 'a list list
('a list -> 'a list) list -> 'a list
'a list list -> 'a list list
'a list -> 'b list -> ('a * 'b) list
('a -> ('b -> 'c)) -> ('a -> 'b) -> ('a -> 'c)
('a -> 'b) -> ('b -> 'a)
('a * 'b) -> 'a
'a -> ('a * 'b)
('a -> ('b -> 'c)) -> (('a * 'b) -> 'c)
'a -> 'b -> 'a * 'b
'a -> 'b -> 'a
('a * 'b) -> ('a -> 'c) -> ('c * 'b)
Hint: To show that a type A is inhabited, it is sufficient
to show that there exists an ML term M which has type A.
To show that a type A is not inhabited, one can proceed in two ways:
fn f => fn g => fn x => (f x) (g x);
fn (x,y) => x;
fun uncurry f (x,y) = f x y;
fn x => fn y => (x,y);
fn x => fn y => x;
fn (x,y) => fn f => (f x, y);
datatype color = white | red | green | blue; datatype 'a btree = emptybt | consbt of 'a * 'a btree * 'a btree; datatype 'a tree = ctree of 'a * 'a tree list;For each of the following functions, say whether it is typeable in ML (given the above declarations), and, in the positive case, give its most general type.
fun f white = [] | f c = [consbt(c,emptybt,emptybt)];
fun f emptybt = white | f t = red;
fun f emptybt = white | f (ctree(c,l)) = c;
fun f (ctree(c,l)) = c :: (f_aux l) and f_aux [] = [] | f_aux (t :: l) = (f t) @ (f_aux l);
color -> color btree list
'a btree -> color
'a tree -> 'a listf_aux has type
'a tree list -> 'a list