Ugly haskell solution for problem 2-4