Problem 4 in Haskell