mirror of
https://github.com/polysemy-research/polysemy.git
synced 2024-12-03 21:13:10 +03:00
Prefer interpret over reinterpret for effect transformers
This commit is contained in:
parent
60696e2035
commit
689998a77d
@ -11,3 +11,7 @@
|
||||
- Initial release
|
||||
|
||||
## Unreleased changes
|
||||
|
||||
- `runInputAsReader`, `runTraceAsOutput` and `runOutputAsWriter` have more
|
||||
generalized types
|
||||
- Aded `runStateInIO`
|
||||
|
@ -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 #-}
|
||||
|
||||
|
@ -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 #-}
|
||||
|
||||
|
@ -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 #-}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user