- ('+ '(abs int (abs int int)))
- ('- '(abs int (abs int int)))
- ('* '(abs int (abs int int)))
- ('! '(abs bool bool))
- ('= '(abs int (abs int bool)))
- ('bool->int '(abs bool int))
- ('print '(abs string void))
- (else #f)))
-
-; we typecheck the lambda calculus only (only single arg lambdas)
-(define (typecheck prog)
- (define (check env x)
- ;; (display "check: ")
- ;; (display x)
- ;; (display "\n\t")
- ;; (display env)
- ;; (newline)
- (let
- ((res
- (case (ast-type x)
- ('int-literal (list '() 'int))
- ('bool-literal (list '() 'bool))
- ('string-literal (list '() 'string))
- ('builtin (list '() (builtin-type x)))
-
- ('if
- (let* ((cond-type-res (check env (cadr x)))
- (then-type-res (check env (caddr x)))
- (else-type-res (check env (cadddr x)))
- (then-eq-else-cs (~ (cadr then-type-res)
- (cadr else-type-res)))
- (cs (consolidate
- (car then-type-res)
- (consolidate (car else-type-res)
- then-eq-else-cs)))
- (return-type (substitute cs (cadr then-type-res))))
- (when (not (eqv? (cadr cond-type-res) 'bool))
- (error #f "if condition isn't bool"))
- (list cs return-type)))
-
- ('var (list '() (env-lookup env x)))
- ('let
+ ('+ '(abs Int (abs Int Int)))
+ ('- '(abs Int (abs Int Int)))
+ ('* '(abs Int (abs Int Int)))
+ ('! '(abs Bool Bool))
+ ('= '(abs Int (abs Int Bool)))
+ ('bool->int '(abs Bool Int))
+ ('print '(abs String Void))
+ (else (error #f "Couldn't find type for builtin" x))))
+
+(define (check-let env x)