Skip to content

Commit f2b9834

Browse files
Racket lumps in ML
1 parent 858015f commit f2b9834

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

tests/dsls/matthews-findler/lump-inferred.rkt

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
(nonterminal ml-type
4343
#:binding-space ml
4444
Nat
45+
L
4546
(-> t1:ml-type t2:ml-type))
4647

4748
(host-interface/expression
@@ -54,23 +55,30 @@
5455
#`(ml->racket #,e^)))
5556

5657
(struct ml-value [v t])
57-
58-
(define (seal e t)
59-
(ml-value e t))
60-
61-
(define (unseal e t)
62-
(unless (ml-value? e)
63-
(error 'MR "not an ML value"))
64-
(let ([v (ml-value-v e)]
65-
[t (ml-value-t e)])
66-
(if (equal? t t)
67-
v
68-
(error 'unseal "type mismatch"))))
58+
(struct racket-value [v])
59+
60+
(define (RM-translation v t)
61+
(if (equal? (syntax->datum t) 'L)
62+
(if (racket-value? v)
63+
(racket-value-v v)
64+
(error 'RM "not a Racket value"))
65+
(ml-value v t)))
66+
67+
(define (MR-translation v t)
68+
(if (equal? (syntax->datum t) 'L)
69+
(racket-value v)
70+
(if (ml-value? v)
71+
(let ([v (ml-value-v v)]
72+
[t (ml-value-t v)])
73+
(if (equal? t t)
74+
v
75+
(error 'MR "type mismatch")))
76+
(error 'MR "not an ML value"))))
6977

7078
(begin-for-syntax
7179
(define (compile-RM e)
7280
(define-values (e^ t) (infer-type e))
73-
#`(seal (ml->racket #,e^) #'#,t))
81+
#`(RM-translation (ml->racket #,e^) #'#,t))
7482

7583
;; No type variables yet, so should just be datum equality.
7684
(define (assert-type-equal! actual expected term)
@@ -163,7 +171,7 @@
163171
[(_ (lambda ([x t]) b))
164172
#'(lambda (x) (ml->racket b))]
165173
[(_ (MR e t))
166-
#'(unseal e #'t)]))
174+
#'(MR-translation e #'t)]))
167175

168176

169177
(module+ test
@@ -188,7 +196,10 @@
188196
(check-equal? (ml ((lambda ([x Nat]) (+ (MR (let ([v x]) v)) 1)) 5))
189197
6)
190198

191-
(ml (lambda ([x Nat]) (+ (MR (RM x)) 1)))
199+
(check-equal?
200+
(racket-value-v (ml (: ((lambda ([x L]) (: (MR (+ x 1)) L)) (: (MR 5) L)) L)))
201+
6)
202+
192203

193204
(check-type-error
194205
(ml (app (lambda ([x Nat]) x) (lambda ([y Nat]) y)))

0 commit comments

Comments
 (0)