Copyright | (c) Michael Szvetits 2023 |
---|---|
License | BSD-3-Clause (see the file LICENSE) |
Maintainer | typedbyte@qualified.name |
Stability | stable |
Portability | portable |
Safe Haskell | Safe-Inferred |
Language | GHC2021 |
A region-based resource effect for the effectful ecosystem.
Synopsis
- data Resource :: Effect
- runResource :: IOE :> es => Eff (Resource ': es) a -> Eff es a
- data Region
- withRegion :: Resource :> es => Eff es a -> Eff es a
- currentRegion :: Resource :> es => Eff es Region
- data Key
- data InvalidKey = InvalidKey
- manage :: Resource :> es => IO a -> (a -> IO b) -> Eff es a
- allocate :: Resource :> es => IO a -> (a -> IO b) -> Eff es (a, Key)
- free :: Key -> Eff es ()
- freeAll :: Foldable t => t Key -> Eff es ()
- move :: Resource :> es => Key -> Region -> Eff es Key
- move_ :: Resource :> es => Key -> Region -> Eff es ()
- defer :: Resource :> es => IO a -> Eff es ()
Resource Effect
data Resource :: Effect Source #
The region-based resource effect.
Instances
type DispatchOf Resource Source # | |
Defined in Effectful.Resource | |
newtype StaticRep Resource Source # | |
Defined in Effectful.Resource |
Manage Regions
A region owns resources and frees them on close.
Manage Resources
Each resource is identified by a unique key.
data InvalidKey Source #
An error which occurs if a key is freed/moved that has already been freed/moved.
Instances
Exception InvalidKey Source # | |
Defined in Effectful.Resource toException :: InvalidKey -> SomeException # fromException :: SomeException -> Maybe InvalidKey # displayException :: InvalidKey -> String # | |
Show InvalidKey Source # | |
Defined in Effectful.Resource showsPrec :: Int -> InvalidKey -> ShowS # show :: InvalidKey -> String # showList :: [InvalidKey] -> ShowS # | |
Eq InvalidKey Source # | |
Defined in Effectful.Resource (==) :: InvalidKey -> InvalidKey -> Bool # (/=) :: InvalidKey -> InvalidKey -> Bool # | |
Ord InvalidKey Source # | |
Defined in Effectful.Resource compare :: InvalidKey -> InvalidKey -> Ordering # (<) :: InvalidKey -> InvalidKey -> Bool # (<=) :: InvalidKey -> InvalidKey -> Bool # (>) :: InvalidKey -> InvalidKey -> Bool # (>=) :: InvalidKey -> InvalidKey -> Bool # max :: InvalidKey -> InvalidKey -> InvalidKey # min :: InvalidKey -> InvalidKey -> InvalidKey # |
:: Resource :> es | |
=> IO a | The computation which acquires the resource. |
-> (a -> IO b) | The computation which releases the resource. |
-> Eff es a | The acquired resource. |
Allocates a resource in the current region which is automatically freed at the end of the region.
:: Resource :> es | |
=> IO a | The computation which acquires the resource. |
-> (a -> IO b) | The computation which releases the resource. |
-> Eff es (a, Key) | The acquired resource and its corresponding key. |
Allocates a resource in the current region which can be moved and freed manually using its key.
move :: Resource :> es => Key -> Region -> Eff es Key Source #
Moves a resource to the specified region, yielding a new key for the resource. The old key is invalid after the movement.