Implement a compiler monad, providing state and error handling