Created
January 10, 2025 13:53
-
-
Save aherrmann/499b58811dcdcbd6721b8820efbd161e to your computer and use it in GitHub Desktop.
ResourcesWithResourceT
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.Trans.Resource | |
import Control.Monad.IO.Class | |
import System.IO | |
main :: IO () | |
main = runResourceT $ do | |
(_, a) <- allocate (openFile "a.txt" ReadMode) hClose | |
(_, b) <- allocate (openFile "b.txt" ReadMode) hClose | |
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