solved #2 in haskell