

f1 x = x + 2
(Num a) => a -> a
But we'll pretend for now it gives int -> int
2 : int + : int -> int -> int x : u (unknown type) f1 : v (unknown type)

x :
u)x + 2 is + x 2 = (+ x) 2 = Apply(Apply(+,x), 2)


v = u -> r s = int -> t int -> int -> int = u -> s
r = t
int -> int -> int = u -> s
-> is right associativeint -> (int -> int) = u -> s
int = u int -> int = s
s = int -> t, int -> int = s
v)v = u -> r = u -> t = int -> t = int -> int
f1 has type int -> intf2 g h = g(h(0))
u = v -> s s = w -> r v = q -> p w = int -> q r = p
You try it!
Hint: r = p tells you that you can use p instead of r.
Remember the goal (u). Keep plugging in until you can't simplify any more.
What do you get? Pay attention to parentheses.
length (x:xs) = 1 + length(xs)

u = s -> r t = w -> s a -> [a] -> [a] = v -> t n = q -> p int -> int -> int = int -> n u = w -> q r = p . . . u = [a] -> int
lab.hs and load it.
f1 x = x + 2
What type do you get? (Simplify Num a to int
throughout in your answers.)
apply f x = f x
What type do you get?
apply f1 3
Try it out to verify your expectation
apply f x = f(x)apply? apply2(f,x) = f(x)
What type does Haskell report?
apply2?rev [] = [] rev (x:xs) = rev xs
What type do you get?
There is an error in the function. It doesn't actually reverse a list. How can you tell that the function is wrong just by looking at the inferred type?