Skip to content

Instantly share code, notes, and snippets.

@carymrobbins
Last active August 29, 2015 14:05
Show Gist options
  • Save carymrobbins/1f46f351d43964668aff to your computer and use it in GitHub Desktop.
Save carymrobbins/1f46f351d43964668aff to your computer and use it in GitHub Desktop.
I was under the impression that ResourceT prevents accessing released resources with the type system. Maybe I am not using it correctly...
import Control.Monad.Trans.Class (lift)
import Control.Monad.Trans.Resource
import System.IO
main = runResourceT $ do
(releaseO, output) <- allocate (openFile "output.txt" WriteMode) hClose
lift $ hPutStrLn output "hallo!"
release releaseO
(releaseI, input) <- allocate (openFile "output.txt" ReadMode) hClose
release releaseI
-- Too bad the next call doesn't cause a type error...
lift $ putStr "Contents: " >> hGetContents input >>= hPutStrLn output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment