CS 3520 Homework 10   - Due November 23

This homework is due November 23, 8:00 AM.

Submit your work using DrScheme's Handin button, even though it's OCaml code. The handin server will not run any tests.

Exercise 10.1, Implementing Polymorphism

Implement the TPFAE language from the November 14 lecture. (The grammar is on slide 14.)

Start with whatever code you like from the slides and previous assignments, or start from scratch. Write test cases; the examples below are not enough.

Examples, using concrete syntax (but you don't need to write a parser):

  [tyfun [x] 10]
  ; typechecks, produce a polymorphic result

  [@ [tyfun [x] 10] (int -> int)]
  ; typechecks, produces 10

  {+ 12 [@ [tyfun [x] 10] (int -> int)]}
  ; typechecks, produces 22

  {[@ [tyfun [alpha] {fun {x : alpha} x}]
      num] 12}  
  ; typechecks, produces 12

  [@ [tyfun [alpha] {fun {x : alpha} x}]
     (forall beta beta)]
  ; typechecks, produces a function from (forall beta beta)
  ;  to (forall beta beta) --- nevermind that no expression
  ;  can have type (forall beta beta), which means that this
  ;  function cannot be applied

  [@ [tyfun [alpha] {fun {x : (forall alpha alpha)} x}]
     (forall beta beta)]
  ; typechecks, produces a function from (forall alpha alpha)
  ;  to (forall alpha alpha)

  {+ [@ [tyfun [alpha] {fun {x : alpha} x}]
        num] 
     12}
  ; doesn't typecheck; attempts to add a function
  ;  to a number
 
  {fun {x : beta} x}
  ; doesn't typecheck; beta is free

  [@ [tyfun [alpha] {fun {x : alpha} x}]
     (forall gamma beta)]
  ; doesn't typecheck; beta is free


Last update: Wednesday, November 23rd, 2005
mflatt@cs.utah.edu