Fast imperative-style loops in Haskell