-->
<!--
-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
-->
; 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))
(\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
-->