Created
January 16, 2019 21:04
-
-
Save aljce/49c1161fad3878a1c12953046a009dd7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
newtype Region s a = Region (IO a) deriving (Functor, Applicative, Monad) | |
liftIO :: IO a -> Region s a | |
liftIO = Region | |
runRegion :: (forall s. Region s a) -> IO a | |
runRegion (Region x) = x | |
newtype Ref s a = Ref (IORef a) | |
newRef :: a -> Region s (Ref s a) | |
newRef x = coerce (newIORef x) | |
-- Type error so invariant maintained | |
-- leak :: Region s (Ref s a) -> IO (Ref s a) | |
-- leak = runRegion |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment