1
1
mirror of https://github.com/github/semantic.git synced 2024-12-20 21:31:48 +03:00

Qualify Eff.

This commit is contained in:
Rob Rix 2018-05-06 14:16:40 -04:00
parent 0334ab0ded
commit 79e5f02108

View File

@ -12,10 +12,11 @@ module Control.Effect
, handleState
) where
import Control.Monad.Effect
import qualified Control.Monad.Effect as Eff
import Control.Monad.Effect.Reader
import Control.Monad.Effect.Resumable
import Control.Monad.Effect.State
import Prologue hiding (throwError)
throwResumable :: (Member (Resumable exc) effects, Effectful m) => exc v -> m effects v
throwResumable = raise . throwError
@ -24,24 +25,24 @@ resume :: (Member (Resumable exc) e, Effectful m) => m e a -> (forall v . (v ->
resume m handle = raise (resumeError (lower m) (\yield -> lower . handle (raise . yield)))
-- | Types wrapping 'Eff' actions.
-- | Types wrapping 'Eff.Eff' actions.
--
-- Most instances of 'Effectful' will be derived using @-XGeneralizedNewtypeDeriving@, with these ultimately bottoming out on the instance for 'Eff' (for which 'raise' and 'lower' are simply the identity). Because of this, types can be nested arbitrarily deeply and still call 'raise'/'lower' just once to get at the (ultimately) underlying 'Eff'.
-- Most instances of 'Effectful' will be derived using @-XGeneralizedNewtypeDeriving@, with these ultimately bottoming out on the instance for 'Eff.Eff' (for which 'raise' and 'lower' are simply the identity). Because of this, types can be nested arbitrarily deeply and still call 'raise'/'lower' just once to get at the (ultimately) underlying 'Eff.Eff'.
class Effectful m where
-- | Raise an action in 'Eff' into an action in @m@.
raise :: Eff effects a -> m effects a
raise :: Eff.Eff effects a -> m effects a
-- | Lower an action in @m@ into an action in 'Eff'.
lower :: m effects a -> Eff effects a
lower :: m effects a -> Eff.Eff effects a
instance Effectful Eff where
instance Effectful Eff.Eff where
raise = id
lower = id
-- Handlers
-- | Raise a handler on 'Eff' to a handler on some 'Effectful' @m@.
raiseHandler :: Effectful m => (Eff effectsA a -> Eff effectsB b) -> m effectsA a -> m effectsB b
-- | Raise a handler on 'Eff.Eff' to a handler on some 'Effectful' @m@.
raiseHandler :: Effectful m => (Eff.Eff effectsA a -> Eff.Eff effectsB b) -> m effectsA a -> m effectsB b
raiseHandler handler = raise . handler . lower
-- | Run a 'Reader' effect in an 'Effectful' context.