instance Member (Final IO) r => Catch.MonadCatch (Sem r) where
catch m handler = withStrategicToFinal @IO $ do
m' <- runS m
st <- getInitialStateS
handler' <- bindS handler
pure $ m' `Catch.catch` \e -> handler' $ e <$ st
mask :: Member (Final IO) r
=> ((forall a. Sem r a -> Sem r a) -> Sem r b)
-> Sem r b
mask f = withWeavingToFinal $ \st lower ins ->
lower $ f (\z -> fmap (fromJust . ins) $ embedFinal @IO $ X.mask $ \y -> y $ lower $ z <$ st) <$ st
Hi friends, I'm playing with polysemy again! Trying to figure out whether I can implement
MonadCatch
viaFinal IO
?yay!
i have to admit i don't really "get" final
is love still involved?
yes, he's been working on a core rewrite for version 2, but he's been very busy lately with thesis and now the new job
this looks right to me
alternatively with
withWeavingToFinal
:both discard
State
thoughBoth of your definitions are correct. Discarding state in the handler is necessary and expected.
can we implement mask?
i got as far as this:
whichi is OBVIOUSLY WRONG
but it does typecheck
not sure this is sound :speechless:
this is v2?
yarr
FYI Love gave an implementation for v1 here: https://github.com/polysemy-research/polysemy/issues/135#issuecomment-530367719
this uses the same approach as I did – running a separate, nested
Final
action for therestore
arglovely, ty
I created a
Mask
withScoped
: https://github.com/tek/polysemy-conc/blob/master/packages/conc/lib/Polysemy/Conc/Interpreter/Mask.hstest: https://github.com/tek/polysemy-conc/blob/master/packages/conc/test/Polysemy/Conc/Test/MaskTest.hs