[Haskell-cafe] Re: [Haskell] Simple IO Regions

Andrew Pimlott andrew at pimlott.net
Thu Jan 19 02:21:09 EST 2006

On Tue, Jan 17, 2006 at 06:13:14PM +0000, Keean Schupke wrote:
>    Just made a few modifications and thought it might be useful to 
> people. I have rewritten the functions as
> "liftR" and "bracketR" over a "MonadIO" monad interface (allowing 
> monad-transformers to be used). This is now
> usable as  Region library, as you can lift any arbitrary IO function 
> into a Region. I don't think I have overlooked anything, and I
> think it is as safe as the original...
> liftR :: (InRegion mark marks) => (h -> m a) -> Private mark h -> Region marks m a
> liftR f (Private h) = Region $ f h 

This is not as safe.  Try modifying your test2:

> -- test2 = bracketR (openFile "/etc/services" ReadMode) (hClose) (\f -> return f)
> -- test2' = bracketR (openFile "/etc/services" ReadMode) (hClose) (\f -> liftR return f)

This returns the "Private" handle out of the region.

Still, these functions would be useful for creating a library of
region-safe operations.


More information about the Haskell-Cafe mailing list