Do problem 9 in Haskell.