bluefin-0.0.14.0: The Bluefin effect system
Safe HaskellSafe-Inferred
LanguageHaskell2010

Bluefin.Eff

Synopsis

Eff monad

data Eff (es :: Effects) a #

Instances

Instances details
Applicative (Eff es) 
Instance details

Defined in Bluefin.Internal

Methods

pure :: a -> Eff es a #

(<*>) :: Eff es (a -> b) -> Eff es a -> Eff es b #

liftA2 :: (a -> b -> c) -> Eff es a -> Eff es b -> Eff es c #

(*>) :: Eff es a -> Eff es b -> Eff es b #

(<*) :: Eff es a -> Eff es b -> Eff es a #

Functor (Eff es) 
Instance details

Defined in Bluefin.Internal

Methods

fmap :: (a -> b) -> Eff es a -> Eff es b #

(<$) :: a -> Eff es b -> Eff es a #

Monad (Eff es) 
Instance details

Defined in Bluefin.Internal

Methods

(>>=) :: Eff es a -> (a -> Eff es b) -> Eff es b #

(>>) :: Eff es a -> Eff es b -> Eff es b #

return :: a -> Eff es a #

Run an Eff

runPureEff :: (forall (es :: Effects). Eff es a) -> a #

Run an Eff that doesn't contain any unhandled effects.

runEff #

Arguments

:: (forall (e :: Effects) (es :: Effects). IOE e -> Eff (e :& es) a) 
-> IO a

͘

Run an Eff whose only unhandled effect is IO.

>>> runEff $ \io -> do
      effIO io (putStrLn "Hello world!")
Hello, world!

Resource management

bracket #

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

-> 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.bracket, whose documentation you can inspect for further details.

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 bracket does 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.
  • Eff itself is able to guarantee that any exceptions thrown in the body will be actually thrown before bracket exits. This is inherited from the fact that Eff is a wrapper around IO.

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.

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.

withMonadIO #

Arguments

:: forall (e :: Effects) (es :: Effects) r. e :> es 
=> IOE e 
-> (forall (m :: Type -> Type). MonadIO m => m r)

MonadIO operation

-> Eff es r

MonadIO operation run in Eff

Run MonadIO operations in Eff.

>>> runEff $ \io -> withMonadIO io $ liftIO $ do
      putStrLn "Hello world!"
Hello, world!

withMonadFail #

Arguments

:: forall (e :: Effects) (es :: Effects) r. e :> es 
=> Exception String e

Exception to throw on fail

-> (forall (m :: Type -> Type). MonadFail m => m r)

MonadFail operation

-> Eff es r

MonadFail operation run in Eff

Run MonadFail operations in Eff.

>>> runPureEff $ try $ \e ->
      when (2 > 1) $
        withMonadFail e (fail "2 was bigger than 1")
Left "2 was bigger than 1"

Effect tracking

data Effects #

Instances

Instances details
Handle (ConstEffect r :: Effects -> Type) 
Instance details

Defined in Bluefin.Internal

Methods

mapHandle :: forall (e :: Effects) (es :: Effects). e :> es => ConstEffect r e -> ConstEffect r es #

class (es1 :: Effects) :> (es2 :: Effects) #

Effect subset constraint

Instances

Instances details
e :> e

A set of effects e is a subset of itself

Instance details

Defined in Bluefin.Internal

e :> (e :& es)

e is a subset of a larger set e :& es

Instance details

Defined in Bluefin.Internal

e :> es => e :> (x :& es)

If e is subset of es then e is a subset of a larger set, x :& es

Instance details

Defined in Bluefin.Internal

type (:&) = 'Union infixr 9 #

type (:&) :: Effects -> Effects -> Effects

Union of effects