Haskell rewrite