Problem 4 in haskell