X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=blobdiff_plain;f=assignment_3_evaluator.mdwn;h=28693f436d9360d5603354a48ecf498e32633e8f;hp=496003d08e11017e54aa4324e7f04a521ce2a60b;hb=4c15241dde4586a70e36948d3a9cb035c33c8e5e;hpb=6a60dbeb81ccc4949724a6db13a264a0b322a22d diff --git a/assignment_3_evaluator.mdwn b/assignment_3_evaluator.mdwn index 496003d0..28693f43 100644 --- a/assignment_3_evaluator.mdwn +++ b/assignment_3_evaluator.mdwn @@ -5,6 +5,8 @@ Here are the definitions pre-loaded for working on assignment 3: let true = \x y. x in let false = \x y. y in let and = \l r. l (r true false) false in +let or = \l r. l true r in +; let make\_pair = \f s g. g f s in let get\_fst = true in let get\_snd = false in @@ -21,7 +23,7 @@ let mylist = make\_list 1 (make\_list 2 (make\_list 3 empty)) in let iszero = \n. n (\x. false) true in let succ = \n s z. s (n s z) in let mul = \m n s. m (n s) in -let pred = \n. iszero n 0 (length (tail (n (\p. make\_list junk p) empty))) in +let pred = (\shift n. n shift (make\_pair 0 0) get\_snd) (\p. p (\x y. make\_pair (succ x) x)) in let leq = \m n. iszero(n pred m) in let eq = \m n. and (leq m n)(leq n m) in ; @@ -40,6 +42,23 @@ let makeList = make\_list in let isZero = iszero in let mult = mul in ; +let t1 = (make_list 1 empty) in +let t2 = (make_list 2 empty) in +let t3 = (make_list 3 empty) in +let t12 = (make_list t1 (make_list t2 empty)) in +let t23 = (make_list t2 (make_list t3 empty)) in +let ta = (make_list t1 t23) in +let tb = (make_list t12 t3) in +let tc = (make_list t1 (make_list t23 empty)) in +; +;sum-leaves t1 ~~> 1 +;sum-leaves t2 ~~> 2 +;sum-leaves t3 ~~> 3 +;sum-leaves t12 ~~> 3 +;sum-leaves t23 ~~> 5 +;sum-leaves ta ~~> 6 +;sum-leaves tb ~~> 6 +; length (tail mylist)