Comment on Use Haskell for shell scriptingparentComments−danidiaz11yWhat's the idiom for chdir'ing to a subdirectory such that you pop back out again when you're doneThis can be done with the "bracket" function, which works roughly like a context manager in Python: import Control.Exception import System.Directory withDirectory :: FilePath -> IO a -> IO a withDirectory path action = bracket (getCurrentDirectory <* setCurrentDirectory path) setCurrentDirectory (const action)
Comments
This can be done with the "bracket" function, which works roughly like a context manager in Python: