; ('a, ('b, 'a))
(define (env-lookup env n)
- (if (null? env) (error #f "empty env") ; it's a type equality
+ (if (null? env) (error #f "empty env" env n) ; it's a type equality
(if (eq? (caar env) n)
(cdar env)
(env-lookup (cdr env) n))))
(check new-env (last (let-body x)))))
(define (check env x)
- (display "check: ")
- (display x)
- (display "\n\t")
- (display env)
- (newline)
+ ;; (display "check: ")
+ ;; (display x)
+ ;; (display "\n\t")
+ ;; (display env)
+ ;; (newline)
(let
((res
(case (ast-type x)
(let ((return-type (substitute cs (caddr resolved-func-type))))
(list cs return-type))
(error #f "not a function")))))))
- (display "result of ")
- (display x)
- (display ":\n\t")
- (display (pretty-type (cadr res)))
- (display "\n\t[")
- (display (pretty-constraints (car res)))
- (display "]\n")
+ ;; (display "result of ")
+ ;; (display x)
+ ;; (display ":\n\t")
+ ;; (display (pretty-type (cadr res)))
+ ;; (display "\n\t[")
+ ;; (display (pretty-constraints (car res)))
+ ;; (display "]\n")
res))
; we typecheck the lambda calculus only (only single arg lambdas)
(define (typecheck prog)
- (define (constructor-type t ctr)
- (fold-left (lambda (acc x) `(abs ,x ,acc)) t (cdr ctr)))
- (define (constructors data-def)
- (let ([type-name (cadr data-def)]
- [ctrs (cddr data-def)])
- (fold-left (lambda (acc ctr)
- (cons (cons (car ctr) (constructor-type type-name ctr))
- acc))
- '()
- ctrs)))
- (let ([init-env (flat-map constructors (program-datas prog))])
+
+ (let ([init-env (flat-map data-tors (program-datas prog))])
(display init-env)
+ (newline)
(cadr (check init-env (normalize (program-body prog))))))
+
; returns a list of constraints
(define (~ a b)
(let ([res (unify? a b)])