Lists and List Comprehensions

  1. Suppose you have two lists of integers, left and right. You want to determine whether those lists are equal, that is, whether they have all the same members in the same order. How would you implement such a list comparison?

Here are some hints.

  • If left is [], what does right have to be for left and right to be equal? (Come on, it's not too hard.)

  • Suppose on the other hand that left has head x and tail xs.

    1. If right is then [], are left and right equal?
    2. If right isn't [], and its head isn't equal to x, are left and right equal?
    3. If right isn't [], and its head is equal to x, what else has to be the case for left and right to be equal?
  • Can you now write a recursive definition of the list_equal function? What's your base case?