Solves problem 4 haskell