forked from jasonhemann/miniKanren
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-infer.ss
79 lines (75 loc) · 2.16 KB
/
test-infer.ss
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
(load "mk.scm")
(define !-
(lambda (exp env t)
(conde
[(symbolo exp) (lookupo exp env t)]
[(fresh (x e t-x t-e)
(== `(lambda (,x) ,e) exp)
(symbolo x)
(not-in-envo 'lambda env)
(== `(-> ,t-x ,t-e) t)
(!- e `((,x . ,t-x) . ,env) t-e))]
[(fresh (rator rand t-x)
(== `(,rator ,rand) exp)
(!- rator env `(-> ,t-x ,t))
(!- rand env t-x))])))
(define lookupo
(lambda (x env t)
(fresh (rest y v)
(== `((,y . ,v) . ,rest) env)
(conde
((== y x) (== v t))
((=/= y x) (lookupo x rest t))))))
(define not-in-envo
(lambda (x env)
(conde
((== '() env))
((fresh (y v rest)
(== `((,y . ,v) . ,rest) env)
(=/= y x)
(not-in-envo x rest))))))
(test-check "types"
(run 10 (q) (fresh (t exp) (!- exp '() t) (== `(,exp => ,t) q)))
'((((lambda (_.0) _.0) => (-> _.1 _.1)) (sym _.0))
(((lambda (_.0) (lambda (_.1) _.1))
=>
(-> _.2 (-> _.3 _.3)))
(=/= ((_.0 lambda)))
(sym _.0 _.1))
(((lambda (_.0) (lambda (_.1) _.0))
=>
(-> _.2 (-> _.3 _.2)))
(=/= ((_.0 _.1)) ((_.0 lambda)))
(sym _.0 _.1))
((((lambda (_.0) _.0) (lambda (_.1) _.1)) => (-> _.2 _.2))
(sym _.0 _.1))
(((lambda (_.0) (lambda (_.1) (lambda (_.2) _.2)))
=>
(-> _.3 (-> _.4 (-> _.5 _.5))))
(=/= ((_.0 lambda)) ((_.1 lambda)))
(sym _.0 _.1 _.2))
(((lambda (_.0) (lambda (_.1) (lambda (_.2) _.1)))
=>
(-> _.3 (-> _.4 (-> _.5 _.4))))
(=/= ((_.0 lambda)) ((_.1 _.2)) ((_.1 lambda)))
(sym _.0 _.1 _.2))
(((lambda (_.0) (_.0 (lambda (_.1) _.1)))
=>
(-> (-> (-> _.2 _.2) _.3) _.3))
(=/= ((_.0 lambda)))
(sym _.0 _.1))
(((lambda (_.0) (lambda (_.1) (lambda (_.2) _.0)))
=>
(-> _.3 (-> _.4 (-> _.5 _.3))))
(=/= ((_.0 _.1)) ((_.0 _.2)) ((_.0 lambda)) ((_.1 lambda)))
(sym _.0 _.1 _.2))
(((lambda (_.0) (lambda (_.1) (_.1 _.0)))
=>
(-> _.2 (-> (-> _.2 _.3) _.3)))
(=/= ((_.0 _.1)) ((_.0 lambda)))
(sym _.0 _.1))
((((lambda (_.0) _.0) (lambda (_.1) (lambda (_.2) _.2)))
=>
(-> _.3 (-> _.4 _.4)))
(=/= ((_.1 lambda)))
(sym _.0 _.1 _.2))))