1 Hints for `list_equal`.
3 * If `left` is `[]`, what does `right` have to be for `left` and `right` to be equal? (Come on, it's not too hard, you can figure it out.)
5 * Suppose on the other hand that `left` has head `left_hd` and tail `left_tl`.
8 <LI>If `right` is then `[]`, are `left` and `right` equal?
9 <LI>If `right` isn't `[]`, and its head isn't equal to `left_hd`, are `left` and `right` equal?
10 <LI>If `right` isn't `[]` and its head *is* equal to `left_hd`, what else has to be the case for `left` and `right` to be equal?
13 * Can you now write a recursive definition of the `list_equal` function?
14 What's your base case?
22 ; deconstruct our sofar-pair
23 sofar (\might_be_equal right_tail.
26 (and (and might_be_equal (not (isempty right_tail))) (eq? hd (head right_tail)))
30 ; we pass along the fold a pair
31 ; (might_for_all_i_know_still_be_equal?, tail_of_reversed_right)
32 ; when left is empty, the lists are equal if right is empty
34 true ; for all we know so far, they might still be equal
37 ; when fold is finished, check sofar-pair
38 (\might_be_equal right_tail. and might_be_equal (isempty right_tail))
42 list_equal [] right = isempty right
43 list_equal (hd:tl) right = and (not (isempty right))
45 (list_equal tl (tail right))
49 list_equal [] = \right -> isempty right
50 list_equal (hd:tl) = let prev = list_equal tl
51 in \right -> and (not (isempty right))
55 Now it fits the pattern of fold_right
57 let list_equal = \left. left (\hd sofar. \right. and (and (not (isempty right)) (eq hd (head right))) (sofar (tail right))) isempty