Module

Control.Monad.Fork.Class

#MonadFork

class MonadFork :: (Type -> Type) -> (Type -> Type) -> Constraintclass (Monad m, Functor f) <= MonadFork f m | m -> f where

Represents Monads which can be forked asynchronously.

Laws:

-- Unjoined suspension is a no-op
suspend a1 *> suspend a2 = suspend a2

-- Suspend/join is identity
suspend >=> join = id

-- Fork/join is identity
fork >=> join = id

-- Join is idempotent
join t *> join t = join t

Members

  • suspend :: forall a. m a -> m (f a)
  • fork :: forall a. m a -> m (f a)
  • join :: forall a. f a -> m a

Instances

#MonadKill

class MonadKill :: Type -> (Type -> Type) -> (Type -> Type) -> Constraintclass (MonadFork f m, MonadThrow e m) <= MonadKill e f m | m -> e f where

Represents Monads which can be killed after being forked.

Laws:

-- Killed suspension is an exception
suspend a >>= \f -> kill e f *> join f = throwError e

-- Suspend/kill is unit
suspend a >>= kill e = pure unit

Members

Instances

#BracketCondition

data BracketCondition e a

Constructors

#MonadBracket

class MonadBracket :: Type -> (Type -> Type) -> (Type -> Type) -> Constraintclass (MonadKill e f m, MonadError e m) <= MonadBracket e f m | m -> e f where

Represents Monads which support cleanup in the presence of async exceptions.

Laws:

bracket a k \_ -> pure r
  = uninterruptible (a >>= k (Completed r))

-- Release failed
bracket a k \_ -> throwError e
  = uninterruptible (a >>= k (Failed e) *> throwError e)

-- Release killed
fork (bracket a k \_ -> never) >>= \f -> kill e f *> void (try (join f))
  = uninterruptible (a >>= k (Killed e))

Members

Instances

Modules