From 689998a77dc948e95313db47807cddd12cdb9118 Mon Sep 17 00:00:00 2001 From: Sandy Maguire Date: Sat, 20 Apr 2019 06:00:55 -0400 Subject: [PATCH] Prefer interpret over reinterpret for effect transformers --- ChangeLog.md | 4 ++++ src/Polysemy/Reader.hs | 4 ++-- src/Polysemy/Trace.hs | 7 +++++-- src/Polysemy/Writer.hs | 4 ++-- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index b77bb65..b9ffd5e 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -11,3 +11,7 @@ - Initial release ## Unreleased changes + +- `runInputAsReader`, `runTraceAsOutput` and `runOutputAsWriter` have more + generalized types +- Aded `runStateInIO` diff --git a/src/Polysemy/Reader.hs b/src/Polysemy/Reader.hs index 4282628..e63d262 100644 --- a/src/Polysemy/Reader.hs +++ b/src/Polysemy/Reader.hs @@ -49,8 +49,8 @@ runReader_b = runReader ------------------------------------------------------------------------------ -- | Transform an 'Input' effect into a 'Reader' effect. -runInputAsReader :: Sem (Input i ': r) a -> Sem (Reader i ': r) a -runInputAsReader = reinterpret $ \case +runInputAsReader :: Member (Reader i) r => Sem (Input i ': r) a -> Sem r a +runInputAsReader = interpret $ \case Input -> ask {-# INLINE runInputAsReader #-} diff --git a/src/Polysemy/Trace.hs b/src/Polysemy/Trace.hs index b16e76d..8ffdbb5 100644 --- a/src/Polysemy/Trace.hs +++ b/src/Polysemy/Trace.hs @@ -43,8 +43,11 @@ runIgnoringTrace = interpret $ \case ------------------------------------------------------------------------------ -- | Transform a 'Trace' effect into a 'Output' 'String' effect. -runTraceAsOutput :: Sem (Trace ': r) a -> Sem (Output String ': r) a -runTraceAsOutput = reinterpret $ \case +runTraceAsOutput + :: Member (Output String) r + => Sem (Trace ': r) a + -> Sem r a +runTraceAsOutput = interpret $ \case Trace m -> output m {-# INLINE runTraceAsOutput #-} diff --git a/src/Polysemy/Writer.hs b/src/Polysemy/Writer.hs index 47135ff..87f41ad 100644 --- a/src/Polysemy/Writer.hs +++ b/src/Polysemy/Writer.hs @@ -32,8 +32,8 @@ makeSem ''Writer ------------------------------------------------------------------------------ -- | Transform an 'Output' effect into a 'Writer' effect. -runOutputAsWriter :: Sem (Output o ': r) a -> Sem (Writer o ': r) a -runOutputAsWriter = reinterpret \case +runOutputAsWriter :: Member (Writer o) r => Sem (Output o ': r) a -> Sem r a +runOutputAsWriter = interpret \case Output o -> tell o {-# INLINE runOutputAsWriter #-}