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