Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fv tests
- --fvTest :: String -> [String] -> IO ()
- makefvTest inp vars
- = TestCase (assertEqual ("for (fvs "++inp++")") (fvs inp) (sort vars))
- -- test expr. expected result
- testfv1 = makefvTest "x" ["x"]
- testfv2 = makefvTest "let x = y in (+ x y)" ["y"]
- testfv3 = makefvTest "((fn x => (+ x y)) y)" ["y"]
- testfv4 = makefvTest fv4 ["x","p"]
- testfv5 = makefvTest fv5 []
- --own tests
- testfv6 = makefvTest fv6 ["x"]
- testfv7 = makefvTest fv7 ["y"]
- testfv8 = makefvTest fv8 []
- fv4 = "((fn p => (p x)) (fn x => (+ x p)))"
- fv5 = "let c = fn x => fn p => (p (* x x)) in "
- ++ " (let inc = fn x => (+ 1 x) in (c 4 inc))"
- fv6 = "let y = (+ y 3) in (+ x y)"
- fv7 = "let x = (+ x y) in (let y = (+ y 1) in (let x = (+ 3 x) in (+ x y)))"
- fv8 = "fn f => f (g x)"
- -- the printed output of the follow looks horrible inside of emacs
- runFvAll = runTestTT $ TestList [ "Test 1" ~: testfv1
- , "Test 2" ~: testfv2
- , "Test 3" ~: testfv3
- , "Test 4" ~: testfv4
- , "Test 5" ~: testfv5
- , "Test 6" ~: testfv6 -- y is bound because it's named, but x isn't
- , "Test 7" ~: testfv7 -- x is bound to a definition, but y isn't
- , "Test 8" ~: testfv8] -- none of the variables are bound to a definition
- subst tests
- st14 = runSubst "let x = (* 7 4) in (- y 1)" "y" "(* 7 4)"
- -- result: let a = (* 7 4) in (- (+ z 3) 1)
- -- Substituting "y" for "(* 7 4)" in "let x = (* 7 4) in (- y 1)" yields
- -- the given answer
- st15 = runSubst "(y (x z))" "z" "fn z => (+ z 1)"
- -- result: (y (x (fn z => (+ z 1))))
- -- Substituting "fn z => (+ z 1)" for the variable "z" in "(y (x z))"
- -- just means plugging the former into the latter
- st16 = runSubst "fn x => (* x y)" "y" "x"
- -- result: (fn a => (* x x))
- -- Substituting "x" for "y" requires a new name for the function
- -- to be determined with fresh, 'a'
- -- e p x
- -- e x p
- runSubAll = do { st1; st2; st3; st4; st5; st6; st7; st8; st9; st10;
- st11; st12; st13; st14; st15; st16
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement