Skip to content

Commit

Permalink
Merge pull request #383 from tek/interpreters-for
Browse files Browse the repository at this point in the history
add InterpretersFor
  • Loading branch information
tek authored Nov 16, 2020
2 parents ade8826 + 5128295 commit 175ccc8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


## Unreleased changes
* Added `InterpretersFor` as a shorthand for interpreters consuming multiple effects

## 1.4.0.0 (2020-10-31)

Expand Down
13 changes: 13 additions & 0 deletions src/Polysemy/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ module Polysemy.Internal
, usingSem
, liftSem
, hoistSem
, Append
, InterpreterFor
, InterpretersFor
, (.@)
, (.@@)
) where
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/Polysemy/Internal/Bundle.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 175ccc8

Please sign in to comment.