Solve problem 2 using Haskell.