X-Git-Url: http://git.lukelau.me/?p=scheme.git;a=blobdiff_plain;f=typecheck.scm;h=821035230affddf4d813074316f5aecaeaa2efc5;hp=4cc93495fb9dd6bc90b03b9b06271e316c65a8bb;hb=844dcd052c6f551d9936693c2b4c49cf920c7051;hpb=869ab36eec3d6422cd56ba968b1e26ed9cef3ed1 diff --git a/typecheck.scm b/typecheck.scm index 4cc9349..8210352 100644 --- a/typecheck.scm +++ b/typecheck.scm @@ -37,7 +37,7 @@ ; ('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)))) @@ -136,11 +136,11 @@ (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) @@ -227,31 +227,24 @@ (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)])