assignment3 tweaks
authorJim Pryor <profjim@jimpryor.net>
Mon, 4 Oct 2010 03:15:32 +0000 (23:15 -0400)
committerJim Pryor <profjim@jimpryor.net>
Mon, 4 Oct 2010 03:15:32 +0000 (23:15 -0400)
Signed-off-by: Jim Pryor <profjim@jimpryor.net>
assignment3.mdwn
assignment_3_evaluator.mdwn

index 8a4efcc..e240b73 100644 (file)
@@ -42,6 +42,7 @@ Recall that version 1 style lists are constructed like this (see
        ; church numerals
        let iszero = \n. n (\x. false) true in
        let succ = \n s z. s (n s z) in
+       let add = \l r. l succ r in
        let mul = \m n s. m (n s) 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
@@ -50,6 +51,7 @@ Recall that version 1 style lists are constructed like this (see
        ; a fixed-point combinator for defining recursive functions
        let Y = \f. (\h. f (h h)) (\h. f (h h)) in
        let length = Y (\length l. isempty l 0 (succ (length (tail l)))) in
+       let fold = Y (\f l g z. isempty l z (g (head l)(f (tail l) g z))) in
        
        eq 2 2 yes no
 
index c4032ee..d7dc94f 100644 (file)
@@ -22,6 +22,7 @@ let mylist = make\_list 1 (make\_list 2 (make\_list 3 empty)) in
 ; church numerals
 let iszero = \n. n (\x. false) true in
 let succ = \n s z. s (n s z) in
+let add = \l r. l succ r in
 let mul = \m n s. m (n s) 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
@@ -29,8 +30,8 @@ let eq = \m n. and (leq m n)(leq n m) in
 ;
 ; a fixed-point combinator for defining recursive functions
 let Y = \f. (\h. f (h h)) (\h. f (h h)) in
-;
 let length = Y (\length l. isempty l 0 (succ (length (tail l)))) in
+let fold = Y (\f l g z. isempty l z (g (head l)(f (tail l) g z))) in
 ;
 ; synonyms
 let makePair = make\_pair in
@@ -60,11 +61,9 @@ let tc = (make\_list t1 (make\_list t23 empty)) in
 ;sum-leaves tb ; ~~> 6
 ;sum-leaves tc ; ~~> 6 
 ;
-let add = \l r. l succ r in
-let fold = Y (\f g l z. isempty l z (g (head l)(f g (tail l) z))) in
-;
+; updated: added add, and fold for v1 lists
 ; hint: 
-fold add mylist 0
+fold mylist add 0
 </textarea>
 
 <input id="PARSE" value="Normalize" type="button">