X-Git-Url: http://git.lukelau.me/?p=scheme.git;a=blobdiff_plain;f=typecheck.scm;h=59e652ad9da26f36906a80964c9956179ecdad9f;hp=eaff75efbe6fdf313e0522216c5e07d2486c75ac;hb=da18430cebcb7b813c9b29841f78d65580c91684;hpb=b936564e4a05bd4a23ec202a1c4919097ace7ca8 diff --git a/typecheck.scm b/typecheck.scm index eaff75e..59e652a 100644 --- a/typecheck.scm +++ b/typecheck.scm @@ -43,6 +43,14 @@ (map normalize (let-body prog)))) (else prog))) +(define (builtin-type x) + (case x + ('+ '(abs int (abs int int))) + ('- '(abs int (abs int int))) + ('* '(abs int (abs int int))) + ('! '(abs bool bool)) + ('bool->int '(abs bool int)) + (else #f))) ; we typecheck the lambda calculus only (only single arg lambdas) (define (typecheck prog) @@ -57,10 +65,8 @@ (cond ((integer? x) (list '() 'int)) ((boolean? x) (list '() 'bool)) - ((eq? x 'inc) (list '() '(abs int int))) - ((eq? x '+) (list '() '(abs int (abs int int)))) + ((builtin-type x) (list '() (builtin-type x))) ((symbol? x) (list '() (env-lookup env x))) - ((let? x) (let ((new-env (fold-left (lambda (acc bind)