Created
January 10, 2025 13:49
-
-
Save aherrmann/3a195e7f02c2f6b5e395aa981fa8b4f7 to your computer and use it in GitHub Desktop.
ResourcesWithManaged
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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