tweak Oleg's rev,list_equal
authorJim Pryor <profjim@jimpryor.net>
Mon, 4 Oct 2010 16:07:28 +0000 (12:07 -0400)
committerJim Pryor <profjim@jimpryor.net>
Mon, 4 Oct 2010 16:07:28 +0000 (12:07 -0400)
Signed-off-by: Jim Pryor <profjim@jimpryor.net>
hints/assignment_4_hint_2.mdwn
lambda_library.mdwn

index 8acdb13..f9f4cf2 100644 (file)
@@ -39,22 +39,22 @@ let list_equal =
 -->
 
 <!--
-eql [] l2        = empty l2
-eql (l1h:l1t) l2 = and (not (empty l2))
-                       (l1h == head l2)
-                       (eql l1t (tail l2))
+list_equal [] right      = isempty right
+list_equal (hd:tl) right = and (not (isempty right))
+                            (hd == head right)
+                            (list_equal tl (tail right))
 
 Rearangement:
 
-eql []        = \l2 -> empty l2
-eql (l1h:l1t) = let prev = eql l1t
-                in \l2 -> and (not (empty l2))
-                              (l1h == head l2)
-                              (prev (tail l2))
+list_equal []      = \right -> isempty right
+list_equal (hd:tl) = let prev = list_equal tl
+                     in \right -> and (not (isempty right))
+                                   (hd == head right)
+                                   (prev (tail right))
 
-Now it fits the pattern of foldr
+Now it fits the pattern of fold_right
 
-let list_equal = \lst. lst (\hd sofar. \lst. and (and (not (isempty lst)) (eq hd (head lst))) (sofar (tail lst))) isempty
+let list_equal = \left. left (\hd sofar. \right. and (and (not (isempty right)) (eq hd (head right))) (sofar (tail right))) isempty
 
 -->
 
index 0c00c45..423ad59 100644 (file)
@@ -65,9 +65,9 @@ and all sorts of other places. Others of them are our own handiwork.
        ; more efficient reverse builds a left-fold instead
        ; make_left_list a (make_left_list b (make_left_list c empty)) ~~> \f z. f c (f b (f a z))
        let reverse = (\make_left_list lst. lst make_left_list empty) (\h t f z. t f (f h z))  in
-       ; most elegant
+       ; from Oleg, of course it's the most elegant
        ; revappend [a;b;c] [x;y] ~~> [c;b;a;x;y]
-       let revappend = \lst. lst (\hd sofar. \lst. sofar (make_list hd lst)) I  in
+       let revappend = \left. left (\hd sofar. \right. sofar (make_list hd right)) I  in
        let rev = \lst. revappend lst empty  in
        ; zip [a;b;c] [x;y;z] ~~> [(a,x);(b,y);(c,z)]
        let zip = \left right. (\base build. reverse left build base (\x y. reverse x))
@@ -331,7 +331,7 @@ let list_equal =
                 (\might_be_equal right_tail. and might_be_equal (isempty right_tail))
 
 ; most elegant
-let list_equal = \lst. lst (\hd sofar. \lst. and (and (not (isempty lst)) (eq hd (head lst))) (sofar (tail lst))) isempty
+let list_equal = \left. left (\hd sofar. \right. and (and (not (isempty right)) (eq hd (head right))) (sofar (tail right))) isempty
 
 -->