Do problem 6 in Haskell.