[Haskell-beginners] general structuring of "foreach" logic in IO