add in Oleg's list_equal
authorJim Pryor <profjim@jimpryor.net>
Mon, 4 Oct 2010 14:18:22 +0000 (10:18 -0400)
committerJim Pryor <profjim@jimpryor.net>
Mon, 4 Oct 2010 14:18:22 +0000 (10:18 -0400)
Signed-off-by: Jim Pryor <profjim@jimpryor.net>
hints/assignment_4_hint_2.mdwn
lambda_library.mdwn

index 5ee63f5..8acdb13 100644 (file)
@@ -15,39 +15,6 @@ What's your base case?
 
 
 <!--
-eql [] l2        = empty l2
-eql (l1h:l1t) l2 = and (not (empty l2))
-                       (l1h == head l2)
-                       (eql l1t (tail l2))
-
-Simple rearangement:
-
-eql []        = \l2 -> empty l2
-eql (l1h:l1t) = \l2 -> and (not (empty l2))
-                       (l1h == head l2)
-                       (eql l1t (tail l2))
-
-and another one rearrangement:
-
-eql []        = \l2 -> empty l2
-eql (l1h:l1t) = let prev = eql l1t
-                in \l2 -> and (not (empty l2))
-                              (l1h == head l2)
-                              (prev (tail l2))
-
-Now it fits the pattern of foldr
-
-So, the end result:
-
-eql = foldr f z
- where
- z = empty
- f h z = \l2 -> and (not (empty l2))
-                    (h == head l2)
-                    (z (tail l2))
--->
-
-<!--
 let list_equal =
     \left right. left
                 ; here's our f
@@ -71,3 +38,23 @@ let list_equal =
                 (\might_be_equal right_tail. and might_be_equal (isempty right_tail))
 -->
 
+<!--
+eql [] l2        = empty l2
+eql (l1h:l1t) l2 = and (not (empty l2))
+                       (l1h == head l2)
+                       (eql l1t (tail l2))
+
+Rearangement:
+
+eql []        = \l2 -> empty l2
+eql (l1h:l1t) = let prev = eql l1t
+                in \l2 -> and (not (empty l2))
+                              (l1h == head l2)
+                              (prev (tail l2))
+
+Now it fits the pattern of foldr
+
+let list_equal = \lst. lst (\hd sofar. \lst. and (and (not (isempty lst)) (eq hd (head lst))) (sofar (tail lst))) isempty
+
+-->
+
index 579668b..0c00c45 100644 (file)
@@ -329,5 +329,9 @@ let list_equal =
                 )
                 ; when fold is finished, check sofar-pair
                 (\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
+
 -->