Copyright | (c) Michael Szvetits 2021 |
---|---|
License | BSD3 (see the file LICENSE) |
Maintainer | typedbyte@qualified.name |
Stability | stable |
Portability | portable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Types and functions for representing programs which run in a specific environment and are able to integrate bracket-like operations.
Synopsis
- data Program e a
- runProgram :: e -> Program e a -> IO a
- bracket :: IO a -> (a -> IO b) -> Program e a
- bracketE :: (e -> IO a) -> (e -> a -> IO b) -> Program e a
- manage :: (forall b. (a -> IO b) -> IO b) -> Program e a
- local :: Program e a -> Program e a
- class Has e t where
- from :: e -> t
- ask :: Program e e
- pull :: e `Has` t => Program e t
- pullWith :: e `Has` t => (t -> IO a) -> Program e a
Program Representation
Represents a program that produces a value of type a
when running in an
environment e
. The required content of the environment is usually described
by declaring Has
constraints on e
.
Turning an IO
action into a Program
is usually done by using liftIO
.
runProgram :: e -> Program e a -> IO a Source #
Runs a program in a given environment e
.
Resource Handling
:: IO a | The computation which acquires the resource. |
-> (a -> IO b) | The computation which releases the resource. |
-> Program e a | The computation which uses the resource. |
Acquire a resource, use it, and then release the resource automatically after the program ends.
bracketE :: (e -> IO a) -> (e -> a -> IO b) -> Program e a Source #
A version of bracket
where the acquisition and release actions may
consult the environment e
.
manage :: (forall b. (a -> IO b) -> IO b) -> Program e a Source #
Integrates a continuation into a Program
, which is useful for integrating
existing bracket-like continuations (often named with...
).
local :: Program e a -> Program e a Source #
Runs a sub-program within a program, which is useful for fine-grained resource handling (i.e., resources acquired by the sub-program are released after the sub-program ends, not at the end of the whole program).
Environment Handling
Demands that a specific value of type t
must be present in the
environment e
.