Problem 3 in Haskell.