Problem 2 in Haskell