A solution to exercise 6-3 in the book Erlang Programming by Cesarini and Thompson