Prefer interpret over reinterpret for effect transformers

This commit is contained in:
Sandy Maguire 2019-04-20 06:00:55 -04:00
parent 60696e2035
commit 689998a77d
4 changed files with 13 additions and 6 deletions

View File

@ -11,3 +11,7 @@
- Initial release
## Unreleased changes
- `runInputAsReader`, `runTraceAsOutput` and `runOutputAsWriter` have more
generalized types
- Aded `runStateInIO`

View File

@ -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 #-}

View File

@ -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 #-}

View File

@ -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 #-}