Matrix/Haskell: refactor file IO