Slow solution in Haskell.