[Haskell-cafe] turning an imperative loop to Haskell