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

📝 the RunEffect instances.

This commit is contained in:
Rob Rix 2017-12-21 10:00:43 -05:00
parent 915d8706f0
commit f842f1423d

View File

@ -39,21 +39,26 @@ class RunEffect f a where
-- | Interpret the topmost effect in a computation with some sensible defaults (defined per-effect), and return the incremental 'Result'. -- | Interpret the topmost effect in a computation with some sensible defaults (defined per-effect), and return the incremental 'Result'.
runEffect :: Eff (f ': fs) a -> Eff fs (Result f a) runEffect :: Eff (f ': fs) a -> Eff fs (Result f a)
-- | 'State' effects with 'Monoid'al states are interpreted starting from the 'mempty' state value into a pair of result value and final state.
instance Monoid b => RunEffect (State b) a where instance Monoid b => RunEffect (State b) a where
type Result (State b) a = (a, b) type Result (State b) a = (a, b)
runEffect = flip runState mempty runEffect = flip runState mempty
-- | 'Reader' effects with 'Monoid'al environments are interpreted starting from the 'mempty' environment value.
instance Monoid b => RunEffect (Reader b) a where instance Monoid b => RunEffect (Reader b) a where
runEffect = flip runReader mempty runEffect = flip runReader mempty
-- | 'Fail' effects are interpreted into 'Either' s.t. failures are in 'Left' and successful results are in 'Right'.
instance RunEffect Fail a where instance RunEffect Fail a where
type Result Fail a = Either String a type Result Fail a = Either String a
runEffect = runFail runEffect = runFail
-- | 'Writer' effects are interpreted into a pair of result value and final log.
instance Monoid w => RunEffect (Writer w) a where instance Monoid w => RunEffect (Writer w) a where
type Result (Writer w) a = (a, w) type Result (Writer w) a = (a, w)
runEffect = runWriter runEffect = runWriter
-- | 'NonDetEff' effects are interpreted into a nondeterministic set of result values.
instance Ord a => RunEffect NonDetEff a where instance Ord a => RunEffect NonDetEff a where
type Result NonDetEff a = Set a type Result NonDetEff a = Set a
runEffect = relay (pure . point) (\ m k -> case m of runEffect = relay (pure . point) (\ m k -> case m of