Implement `resolve` and adjust the unit tests for it.
Chris Pressey
2 years ago
232 | 232 |
)
|
233 | 233 |
where replace_all = fun(t, m, x) ->
|
234 | 234 |
destruct(t,
|
235 | |
fun(n) -> if n == m then v else n,
|
|
235 |
fun(n) -> if n == m then x else var(n),
|
236 | 236 |
fun(u, v) -> app(replace_all(u, m, x), replace_all(v, m, x))
|
237 | 237 |
fun(u, n) -> abs(n, replace_all(u, m, x))
|
238 | 238 |
)
|
35 | 35 |
test3b = (freevars testAbs) == []
|
36 | 36 |
test3c = (freevars (app (var n) (var n))) == [n]
|
37 | 37 |
|
38 | |
--test4a = (show $ resolve (testApp) (var "q")) == "App (Abs (BoundVar 0)) (FreeVar \"n\")"
|
39 | |
--test4b = (show $ resolve (abs "n" (var "m")) (var "q")) == "FreeVar \"m\""
|
40 | |
--test4c = (show $ resolve (abs "n" (var "n")) (var "q")) == "FreeVar \"q\""
|
|
38 |
resolve t x = destruct t
|
|
39 |
(\n -> t)
|
|
40 |
(\u v -> t)
|
|
41 |
(\u n -> replaceAll u n x)
|
|
42 |
where
|
|
43 |
replaceAll t m x = destruct t
|
|
44 |
(\n -> if n == m then x else (var n))
|
|
45 |
(\u v -> app (replaceAll u m x) (replaceAll v m x))
|
|
46 |
(\u n -> abs n (replaceAll u m x))
|
|
47 |
|
|
48 |
q = ["q"]
|
|
49 |
|
|
50 |
test4a = (show $ resolve (testApp) (var q)) == "App (Abs (BoundVar 0)) (FreeVar [\"n\"])"
|
|
51 |
test4b = (show $ resolve (abs n (var m)) (var q)) == "FreeVar [\"m\"]"
|
|
52 |
test4c = (show $ resolve (abs n (var n)) (var q)) == "FreeVar [\"q\"]"
|