Completed problem 7 in Haskell