Skip to content

Instantly share code, notes, and snippets.

@aljce
Created January 16, 2019 21:04
Show Gist options
  • Save aljce/49c1161fad3878a1c12953046a009dd7 to your computer and use it in GitHub Desktop.
Save aljce/49c1161fad3878a1c12953046a009dd7 to your computer and use it in GitHub Desktop.
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