The language for this homework is:
#lang plait |
In this homework you will start with Typed infered Language with lists, functions, numbers, and booleans (a typed toy language, partially extended to support lists). This is the same as as tifae from class, with
Update the following to get typechecking and evaluating lists working.
;; lists of numbers (test (run `{list 1 2}) (ListV (list (NumV 1) (NumV 2)))) (test/type `{list 1 2} (ListT (NumT))) ;; lists of booleans (test (run `{list false true}) (ListV (list (BoolV #f) (BoolV #t)))) ;; report error for mixed types (test/notype `{list 1 true}) ;; infer type of list (test/type `{lam {x : num} {list x}} (ArrowT (NumT) (ListT (NumT)))) ;; report error for mixed inferred types (test/notype `{lam {x : num} {list true x}}) ;; infer type of function parameter from list element (test/type `{lam {x : ?} {list x 1}} (ArrowT (NumT) (ListT (NumT)))) ;; complain about cyclic type (Y-combinator) inside list (test/notype `{lam {x : ?} {list {x x}}}) ;; infer type of list from function application (test/type `{{lam {x : ?} {list x}} 2} (ListT (NumT))) |
Add a builtin Cons to FAE. This should have a similar type signature to plait’s cons (and indeed will most likely use cons in its implementation).
You can simplify your implementation of interp for Cons by assuming the code being evaluated passes the typechecker.
Your code should pass (at least) these tests:
;; cons to empty list (test (run `{cons 1 {list}}) (ListV (list (NumV 1)))) (test/type `{cons 1 {list}} (ListT (NumT))) ;; cons to non-empty list (test (run `{cons 1 {list 2}}) (ListV (list (NumV 1) (NumV 2)))) (test/type `{cons 1 {list 2}} (ListT (NumT))) ;; infer type of cons (test/type `{lam {x : ?} {cons x {list 1}}} (ArrowT (NumT) (ListT (NumT)))) ;; inferen ;; report error for cyclic type (test/notype `{lam {x : ?} {cons x x}}) |
Define minutes-spent as the number of minutes you spent on your homework.