Skip to content

Instantly share code, notes, and snippets.

@aherrmann
Created January 10, 2025 13:53
Show Gist options
  • Save aherrmann/499b58811dcdcbd6721b8820efbd161e to your computer and use it in GitHub Desktop.
Save aherrmann/499b58811dcdcbd6721b8820efbd161e to your computer and use it in GitHub Desktop.
ResourcesWithResourceT
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