Refactoring to a monad in the whole compiler