git @ Cat's Eye Technologies Lariat / 49b476a
Implement `resolve` and adjust the unit tests for it. Chris Pressey 2 years ago
2 changed file(s) with 16 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
232232 )
233233 where replace_all = fun(t, m, x) ->
234234 destruct(t,
235 fun(n) -> if n == m then v else n,
235 fun(n) -> if n == m then x else var(n),
236236 fun(u, v) -> app(replace_all(u, m, x), replace_all(v, m, x))
237237 fun(u, n) -> abs(n, replace_all(u, m, x))
238238 )
3535 test3b = (freevars testAbs) == []
3636 test3c = (freevars (app (var n) (var n))) == [n]
3737
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\"]"