solved problem 8 with haskell