Lecture 1
Lecture 2
Lecture 3
Lecture 4
Lecture 5


Empty lists are already flattened. To flatten a non-empty list, we have to flatten the head of the list and the tail of the list. The resulting lists (i.e., the flattened head and tail) have to be concatenated.

Note that the head of a list is not necessarily a list. It can be any other Prolog term, in which case flattening them does not really make any sense. You have to keep this in mind and deal with these cases properly.


Back to the exercise.