Completed problem 2 in Haskell