add InterpretersFor

This commit is contained in:
Torsten Schmits 2020-10-29 23:38:46 +01:00
parent ade8826e1c
commit 5128295c8c
3 changed files with 19 additions and 5 deletions

View File

@ -2,6 +2,7 @@
## Unreleased changes
* Added `InterpretersFor` as a shorthand for interpreters consuming multiple effects
## 1.4.0.0 (2020-10-31)

View File

@ -34,7 +34,9 @@ module Polysemy.Internal
, usingSem
, liftSem
, hoistSem
, Append
, InterpreterFor
, InterpretersFor
, (.@)
, (.@@)
) where
@ -579,6 +581,11 @@ runM (Sem m) = m $ \z ->
{-# INLINE runM #-}
type family Append l r where
Append (a ': l) r = a ': (Append l r)
Append '[] r = r
------------------------------------------------------------------------------
-- | Type synonym for interpreters that consume an effect without changing the
-- return value. Offered for user convenience.
@ -592,6 +599,12 @@ runM (Sem m) = m $ \z ->
type InterpreterFor e r = a. Sem (e ': r) a -> Sem r a
------------------------------------------------------------------------------
-- | Variant of 'InterpreterFor' that takes a list of effects.
-- @since (TODO)
type InterpretersFor es r = a. Sem (Append es r) a -> Sem r a
------------------------------------------------------------------------------
-- | Some interpreters need to be able to lower down to the base monad (often
-- 'IO') in order to function properly --- some good examples of this are

View File

@ -2,16 +2,16 @@
{-# OPTIONS_HADDOCK not-home #-}
module Polysemy.Internal.Bundle where
module Polysemy.Internal.Bundle (
module Polysemy.Internal.Bundle,
Append,
) where
import Data.Proxy
import Polysemy
import Polysemy.Internal (Append)
import Polysemy.Internal.Union
type family Append l r where
Append (a ': l) r = a ': (Append l r)
Append '[] r = r
extendMembership :: forall r r' e. ElemOf e r -> ElemOf e (Append r r')
extendMembership Here = Here
extendMembership (There e) = There (extendMembership @_ @r' e)