Skip to content

Instantly share code, notes, and snippets.

@aherrmann
Created January 10, 2025 13:49
Show Gist options
  • Save aherrmann/3a195e7f02c2f6b5e395aa981fa8b4f7 to your computer and use it in GitHub Desktop.
Save aherrmann/3a195e7f02c2f6b5e395aa981fa8b4f7 to your computer and use it in GitHub Desktop.
ResourcesWithManaged
import Control.Monad.Managed.Safe
import Control.Monad.IO.Class
import System.IO
main :: IO ()
main = runManaged $ do
a <- managed $ withFile "a.txt" ReadMode
b <- managed $ withFile "b.txt" ReadMode
aContents <- liftIO $ hGetContents a
bContents <- liftIO $ hGetContents b
liftIO . putStrLn $ "contents of a: " <> show aContents
liftIO . putStrLn $ "contents of b: " <> show bContents
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment