Add the subsume handler for deduplicating effects

This commit is contained in:
Alexis King 2017-12-07 16:10:29 -08:00
parent 9b3ca1df06
commit 3c09ca2c6d

View File

@ -217,6 +217,7 @@ module Control.Monad.Freer
-- *** Basic effect handlers
, interpret
, interpose
, subsume
-- *** Derived effect handlers
, reinterpret
, reinterpret2
@ -265,6 +266,12 @@ interpose :: forall eff effs. Member eff effs => (eff ~> Eff effs) -> Eff effs ~
interpose f = interposeWith (\e -> (f e >>=))
{-# INLINE interpose #-}
-- | Interprets an effect in terms of another identical effect. This can be used
-- to eliminate duplicate effects.
subsume :: forall eff effs. Member eff effs => Eff (eff ': effs) ~> Eff effs
subsume = interpret send
{-# INLINE subsume #-}
-- | Like 'interpret', but instead of removing the interpreted effect @f@,
-- reencodes it in some new effect @g@.
reinterpret :: forall f g effs. (f ~> Eff (g ': effs)) -> Eff (f ': effs) ~> Eff (g ': effs)