Solve Problem 7 in Haskell