|
20 | 20 | (list (quote elems) ...))))
|
21 | 21 |
|
22 | 22 | (begin-for-syntax
|
| 23 | + (define-splicing-syntax-class result |
| 24 | + (pattern (~seq) #:with v #'#f) |
| 25 | + (pattern (~seq #:result v:expr))) |
23 | 26 | (define-splicing-syntax-class vars
|
24 | 27 | (pattern (~seq) #:with vars #'empty)
|
25 |
| - (pattern (~seq #:vars vars:expr) )) |
| 28 | + (pattern (~seq #:vars vars:expr))) |
26 | 29 | (define-splicing-syntax-class indices
|
27 | 30 | (pattern (~seq) #:with indices #'empty)
|
28 |
| - (pattern (~seq #:indices indices:expr) )) |
| 31 | + (pattern (~seq #:indices indices:expr))) |
29 | 32 | (define-splicing-syntax-class pass
|
30 | 33 | (pattern (~seq) #:with pass #'#t)
|
31 | 34 | (pattern #:pass #:with pass #'#t)
|
32 | 35 | (pattern #:fail #:with pass #'#f)))
|
33 | 36 |
|
34 | 37 | (define-syntax (infer-t stx)
|
35 | 38 | (syntax-parse stx
|
36 |
| - ([_ S:expr T:expr :vars :indices :pass] |
| 39 | + ([_ S:expr T:expr R:result :vars :indices :pass] |
37 | 40 | (syntax/loc stx
|
38 | 41 | (test-case (format "~a ~a~a" S T (if pass "" " should fail"))
|
39 |
| - (define result (infer vars indices (list S) (list T) #f)) |
40 |
| - (unless (equal? result pass) |
| 42 | + (define result (infer vars indices (list S) (list T) R.v)) |
| 43 | + (unless (if pass result (not result)) |
41 | 44 | (fail-check "Could not infer a substitution")))))))
|
42 | 45 |
|
43 | 46 | (define-syntax (infer-l stx)
|
44 | 47 | (syntax-parse stx
|
45 |
| - ([_ S:expr T:expr :vars :indices :pass] |
| 48 | + ([_ S:expr T:expr R:result :vars :indices :pass] |
46 | 49 | (syntax/loc stx
|
47 | 50 | (test-case (format "~a ~a~a" S T (if pass "" " should fail"))
|
48 |
| - (define result (infer vars indices S T #f)) |
49 |
| - (unless (equal? result pass) |
| 51 | + (define result (infer vars indices S T R.v)) |
| 52 | + (unless (if pass result (not result)) |
50 | 53 | (fail-check "Could not infer a substitution")))))))
|
51 | 54 |
|
52 | 55 |
|
|
87 | 90 | (test-suite "Tests for infer"
|
88 | 91 | (infer-t Univ Univ)
|
89 | 92 | (infer-t (-v a) Univ)
|
| 93 | + (infer-t (-v a) (-v a) #:result (-v a)) |
90 | 94 | (infer-t Univ (-v a) #:fail)
|
91 | 95 | (infer-t Univ (-v a) #:vars '(a))
|
92 | 96 | (infer-t (-v a) Univ #:vars '(a))
|
|
101 | 105 | (infer-t (make-ListDots -Symbol 'b) (make-ListDots Univ 'b) #:indices '(b))
|
102 | 106 | (infer-t (make-ListDots (-v b) 'b) (make-ListDots (-v b) 'b) #:indices '(b))
|
103 | 107 | (infer-t (make-ListDots (-v b) 'b) (make-ListDots Univ 'b) #:indices '(b))
|
| 108 | + (infer-t (-pair (-v a) (make-ListDots (-v b) 'b)) |
| 109 | + (-pair (-v a) (make-ListDots (-v b) 'b)) |
| 110 | + #:result (-v a)) |
104 | 111 |
|
105 | 112 | [infer-t (->... null ((-v a) a) (-v b)) (-> -Symbol -String) #:vars '(b) #:indices '(a)]
|
106 | 113 | [infer-t (->... null ((-v a) a) (make-ListDots (-v a) 'a)) (-> -String -Symbol (-lst* -String -Symbol)) #:indices '(a)]
|
|
0 commit comments