How to add a finalizer for an effect action? #85
Answered
by
mmhat
MuhammedZakir
asked this question in
Q&A
-
I have two effects: data E1 :: Effect where
GetStuff :: E1 m Stuff
DiscardStuff :: Stuff -> E1 m ()
-- 'E1' effect is necessary for 'E2'
data E2 :: Effect where
FuncThatUseStuff :: E2 m () There are two ways
use1 = do
s <- getStuff
...
discardStuff s
use2 = do
s1 <- getStuff
s2 <- getStuff
...
discardStuff s1
-- user didn't discard `s2`, so I'll have to handle it The problem is, I don't know how attach a finalizer without using continuation / passing function:
I am using free monad interpreter atm. In it, I did something like: run = \case
...
GetStuff nextFn -> do
s <- pop
save s
res <- run (nextFn s)
`finally` (handleIfNotDiscarded s)
deleteSaved s
pure res
... |
Beta Was this translation helpful? Give feedback.
Answered by
mmhat
Aug 16, 2022
Replies: 1 comment 1 reply
-
It seems like resourcet-effectful would work for. Just reinterpret |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
arybczak
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It seems like resourcet-effectful would work for. Just reinterpret
E1
in terms of theResource
effect.