Problem 3 in haskell