-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bind.hs
43 lines (36 loc) · 1.03 KB
/
Bind.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
{-# LANGUAGE TemplateHaskell #-}
module Bind where
import Data.Kind
import Polysemy
import Polysemy.Final
data BindE (m :: Type -> Type) a where
BindE :: m a -> (a -> m b) -> BindE m b
makeSem ''BindE
interpretBindFinal :: Member (Final IO) r => InterpreterFor BindE r
interpretBindFinal =
interpretFinal @IO $
\case
BindE f g -> do
fa <- runS f
ff <- bindS g
pure $ fa >>= ff
interpretBindTacticLowering :: forall r. Member (Embed IO) r => InterpreterFor BindE r
interpretBindTacticLowering =
interpretH $
\case
BindE f g -> do
ma <- runT f
mf <- bindT g
withLowerToIO $ \lower _ -> do
let toIO :: Sem (BindE ': r) x -> IO x
toIO = lower . raise . interpretBindTacticLowering
toIO ma >>= toIO . mf
interpretBindTactic :: InterpreterFor BindE r
interpretBindTactic =
interpretH $
\case
BindE f g -> do
ma <- runT f
mf <- bindT g
let runHoE = raise . interpretBindTactic
runHoE ma >>= runHoE . mf