0

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).

Sam Tobin-Hochstadt
  • 4,983
  • 1
  • 21
  • 43
Phea Duch
  • 15
  • 4
  • I'm actually having trouble understanding the question... aren't they all lambdas? How are their data types different in the first place? – user541686 Aug 15 '12 at 03:37
  • Yes they are all lambdas which is why you have to use general A,B,C notation instead of things like number->number. The slides are here and it's the last couple slides that deal with this type of question. [link for slides](https://docs.google.com/viewer?url=http%3A%2F%2Ficampustutor.csail.mit.edu%2F6.001-public%2Fcourseexport%2Flessons%2FLesson6%2Flecture6.pdf) – Phea Duch Aug 15 '12 at 03:43

1 Answers1

2
  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)

C. K. Young
  • 219,335
  • 46
  • 382
  • 435