From 75206940a98f7487da8a0398ab5de12fbafe3a71 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Sat, 7 Jan 2023 09:08:19 -0500 Subject: Add begin form. --- infer2.scm | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/infer2.scm b/infer2.scm index 569792d..18f8ef2 100644 --- a/infer2.scm +++ b/infer2.scm @@ -147,6 +147,12 @@ (make-texp (texp-types body*) `(let ,(map list vars vals*) ,body*))) +(define-matcher (annotate:begin ('begin exps ... last) env) + (define last* (annotate-exp last env)) + (make-texp (texp-types last*) + `(begin ,@(map (lambda (exp) (annotate-exp exp env)) exps) + ,last*))) + (define-matcher (annotate:lambda ('lambda ((? symbol? args) ...) body) env) (define parameter-types (map (lambda (_name) (fresh-type-variable)) args)) (define env* (append (map cons args parameter-types) env)) @@ -171,6 +177,7 @@ annotate:if annotate:values annotate:let + annotate:begin annotate:lambda annotate:call)) @@ -218,6 +225,10 @@ (append (program-constraints body) (append-map program-constraints vals))) +(define-matcher (constrain:begin ((? type? types) ...) + ('begin (? texp? texps) ...)) + (append-map program-constraints texps)) + (define-matcher (constrain:lambda ((? procedure-type? type)) ('lambda ((? symbol? args) ...) (? texp? body))) @@ -237,6 +248,7 @@ (compose-matchers constrain:if constrain:values constrain:let + constrain:begin constrain:lambda constrain:call constrain:other)) -- cgit v1.2.3