mirror of
https://github.com/github/semantic.git
synced 2024-12-30 02:14:20 +03:00
Qualify Eff.
This commit is contained in:
parent
0334ab0ded
commit
79e5f02108
@ -12,10 +12,11 @@ module Control.Effect
|
|||||||
, handleState
|
, handleState
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Control.Monad.Effect
|
import qualified Control.Monad.Effect as Eff
|
||||||
import Control.Monad.Effect.Reader
|
import Control.Monad.Effect.Reader
|
||||||
import Control.Monad.Effect.Resumable
|
import Control.Monad.Effect.Resumable
|
||||||
import Control.Monad.Effect.State
|
import Control.Monad.Effect.State
|
||||||
|
import Prologue hiding (throwError)
|
||||||
|
|
||||||
throwResumable :: (Member (Resumable exc) effects, Effectful m) => exc v -> m effects v
|
throwResumable :: (Member (Resumable exc) effects, Effectful m) => exc v -> m effects v
|
||||||
throwResumable = raise . throwError
|
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)))
|
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
|
class Effectful m where
|
||||||
-- | Raise an action in 'Eff' into an action in @m@.
|
-- | 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 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
|
raise = id
|
||||||
lower = id
|
lower = id
|
||||||
|
|
||||||
|
|
||||||
-- Handlers
|
-- Handlers
|
||||||
|
|
||||||
-- | Raise a handler on 'Eff' to a handler on some 'Effectful' @m@.
|
-- | Raise a handler on 'Eff.Eff' to a handler on some 'Effectful' @m@.
|
||||||
raiseHandler :: Effectful m => (Eff effectsA a -> Eff effectsB b) -> m effectsA a -> m effectsB b
|
raiseHandler :: Effectful m => (Eff.Eff effectsA a -> Eff.Eff effectsB b) -> m effectsA a -> m effectsB b
|
||||||
raiseHandler handler = raise . handler . lower
|
raiseHandler handler = raise . handler . lower
|
||||||
|
|
||||||
-- | Run a 'Reader' effect in an 'Effectful' context.
|
-- | Run a 'Reader' effect in an 'Effectful' context.
|
||||||
|
Loading…
Reference in New Issue
Block a user