regions-0.4: Provides the region monad for safely opening and working with scarce resources.Source codeContentsIndex
MaintainerBas van Dijk <>
Unsafely opening and closing of scarce resources.
class Resource resource where
data Handle resource :: *
openResource :: resource -> IO (Handle resource)
closeResource :: Handle resource -> IO ()
class Resource resource whereSource

Class of scarce resources. A scarce resource is a resource that only one user can use at a time. (like a file, memory pointer or USB device for example).

Because of the scarcity, these resources need to be opened to grant temporary sole access to the resource. When the resource is no longer needed it should be closed a.s.a.p to grant others access to the resource.

Associated Types
data Handle resource :: *Source
openResource :: resource -> IO (Handle resource)Source

Yield an IO computation that opens the given resource and returns a Handle on it.

Think of a handle as your private session with the resource. As long as you have it, other users can't use the resource. So don't forget to close this session with the resource as soon as you're done with it.

closeResource :: Handle resource -> IO ()Source

Yield an IO computation that closes the resource identified by the given Handle.

Warning: Using the Handle after the resource has been closed will usually throw an exception or result in a program crash!

Produced by Haddock version 2.6.0