Question

This is from the MIT 6.001 Online Tutor, it's part of the third problem set.

Question: Indicate the type of each of the following expressions. If you need type variables, use A,B,C, etc., starting with A as the leftmost variable.

  1. (lambda (x y) x) = A,B->A
  2. (lambda (p) (p 3))
  3. (lambda (p x) (p x)) = (A->B), A->B
  4. (lambda (x y comp) (if (comp x y) x y))

As you can see I solved 1 and 3, but that was mainly out of luck. I still am having issues with understanding the concept and that is stopping me from solving 2 and 4.

Lecture slides can be found here (view the last few).

Was it helpful?

Solution

  1. A, B -> A
  2. (number -> A) -> A
  3. (A -> B), A -> B
  4. A, A, (A, A -> boolean) -> A

(the last assumes that x and y are the same types)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top