Haskell program for problem 2