projects
/
scheme.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
54729d0
)
Start work on collecting all bindings when typechecking nested pattern match
author
Luke Lau
<luke_lau@icloud.com>
Thu, 15 Aug 2019 16:36:32 +0000
(17:36 +0100)
committer
Luke Lau
<luke_lau@icloud.com>
Thu, 15 Aug 2019 16:36:32 +0000
(17:36 +0100)
typecheck.scm
patch
|
blob
|
history
diff --git
a/typecheck.scm
b/typecheck.scm
index c6b90e701f467d1651d87c434441b4305ea98742..b3466751fdf7f4161963d3904c13f970b8798a76 100644
(file)
--- a/
typecheck.scm
+++ b/
typecheck.scm
@@
-191,6
+191,16
@@
(define (check-case dls env x)
(define (check-match switch-type x)
(define (check-case dls env x)
(define (check-match switch-type x)
+
+ (define (get-bindings product-types pattern)
+ (define (go product-type product)
+ (case (ast-type x)
+ ['var (list (cons product product-type))]
+ ; an inner pattern match
+ ['app (get-bindings product-type product)]))
+ (flat-map go product-types (cdr pattern)))
+
+
(let ([pattern (car x)]
[expr (cadr x)])
(case (ast-type pattern)
(let ([pattern (car x)]
[expr (cadr x)])
(case (ast-type pattern)
@@
-199,8
+209,8
@@
(let ([sum (assoc (car pattern) (cdr (assoc switch-type dls)))])
(unless sum (error #f "can't pattern match ~a with ~a" switch-type pattern))
(let* ([names (cdr pattern)]
(let ([sum (assoc (car pattern) (cdr (assoc switch-type dls)))])
(unless sum (error #f "can't pattern match ~a with ~a" switch-type pattern))
(let* ([names (cdr pattern)]
- [types (cdr sum)]
- [new-env (
fold-left env-insert env names types
)])
+ [
product-
types (cdr sum)]
+ [new-env (
append (get-bindings product-types pattern) env
)])
(check dls new-env expr)))]
; pattern match with binding and no constructor
['var (check dls (env-insert env pattern switch-type) expr)]
(check dls new-env expr)))]
; pattern match with binding and no constructor
['var (check dls (env-insert env pattern switch-type) expr)]