| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Bluefin.Eff
Synopsis
- data Eff (es :: Effects) a
- runPureEff :: (forall (es :: Effects). Eff es a) -> a
- runEff_ :: (forall (e :: Effects). IOE e -> Eff e a) -> IO a
- runEff :: (forall (e :: Effects) (es :: Effects). IOE e -> Eff (e :& es) a) -> IO a
- bracket :: forall (es :: Effects) a b. Eff es a -> (a -> Eff es ()) -> (a -> Eff es b) -> Eff es b
- finally :: forall (es :: Effects) b. Eff es b -> Eff es () -> Eff es b
- withMonadIO :: forall (e :: Effects) (es :: Effects) r. e <: es => IOE e -> (forall (m :: Type -> Type). MonadIO m => m r) -> Eff es r
- withMonadFail :: forall (e :: Effects) (es :: Effects) r. e <: es => Exception String e -> (forall (m :: Type -> Type). MonadFail m => m r) -> Eff es r
- data Effects
- class (es1 :: Effects) :> (es2 :: Effects)
- type (<:) = (:>)
- type (:&) = 'Union
Eff monad
Instances
| e <: es => OneWayCoercible (Eff e r :: Type) (Eff es r :: Type) | |
Defined in Bluefin.Internal Methods oneWayCoercibleImpl :: OneWayCoercibleD (Eff e r) (Eff es r) # | |
| MonadFix (Eff es) | |
Defined in Bluefin.Internal | |
| Applicative (Eff es) | |
| Functor (Eff es) | |
| Monad (Eff es) | |
| e <: es => OneWayCoercible (Eff e :: Type -> Type) (Eff es :: Type -> Type) | |
Defined in Bluefin.Internal Methods oneWayCoercibleImpl :: OneWayCoercibleD (Eff e) (Eff es) # | |
Run an Eff
runPureEff :: (forall (es :: Effects). Eff es a) -> a #
Run an Eff that doesn't contain any unhandled effects.
Resource management
Arguments
| :: forall (es :: Effects) a b. Eff es a | Acquire the resource |
| -> (a -> Eff es ()) | Release the resource |
| -> (a -> Eff es b) | Run the body with resource |
| -> Eff es b |
bracket acquire release body: acquire a resource, perform the
body with it, and release the resource even if body threw an
exception. This is essentially the same as
Control.Exception., whose
documentation you can inspect for further details.bracket
bracket has a very general type that does not require es to
contain an exception or IO effect. The reason that this is safe is:
- While
bracketdoes catch exceptions, this is unobservable, since the exception is re-thrown; the cleanup action happens unconditionally; and no part of it gets access to the thrown exception. Effitself is able to guarantee that any exceptions thrown in the body will be actually thrown beforebracketexits. This is inherited from the fact thatEffis a wrapper aroundIO.
While it is usually the case that the cleanup action will in fact
want to use IO effects, this is not universally true, see the
polymorphicBracket example for an example.
Arguments
| :: forall (es :: Effects) b. Eff es b | Body |
| -> Eff es () | Final action to run after the body, regardless of whether the body terminated normally or via exception |
| -> Eff es b |
A simpler variant of bracket for use when you don't need to
acquire a resource.
Type classes
See Bluefin.Eff.IO for the most direct way of doing I/O in
Bluefin. If you really want to use MonadIO you can use
withMonadIO.
Effect tracking
Each inhabitant of Effects is a set of effect tags, used for
effect tracking to ensure that effects don't escape the scope of
their handler
Instances
class (es1 :: Effects) :> (es2 :: Effects) #
The subset constraint on sets of effect tags
Please use the type synonym <: instead of :>. The former is a
better name for this constraint and :> will be renamed <: in a
future version.
Instances
| e :> e | A set of effects |
Defined in Bluefin.Internal | |
| e :> (e :& es) |
|
Defined in Bluefin.Internal | |
| e :> es => e :> (x :& es) | If |
Defined in Bluefin.Internal | |
The subset constraint on sets of effect tags. <: is a type
operator (see the extension TypeOperators) so in order to import
it you need to use the ExplicitNamespaces extension and the
type import qualifier, like this:
{-# LANUGAGE ExplicitNamespaces #-}
import Bluefin.Eff (type (<:))
"<:" is a synonym for ":>". "<:" is a better name for
this constraint than ":>" because it is more evocative of
mathematical relations like <, <=, ⊂ and ⊆ which hold when
the argument on the left of the operator is "smaller than" the
argument on the right. In the case of <: we have that e1 <: e2
when the set of effect tags e1 is a subset of or equal to e2,
i.e. "e1 is smaller than (or equal to) e2". For example, the
following constraints hold (note that :& is the union of sets of
effect tags):
e <: e
e <: (e1 :& ... :& e :& ... :& en)