Closed isovector closed 5 years ago
This actually becomes implementable once https://github.com/polysemy-research/polysemy/pull/187 is merged. (The current semantics of Fixpoint
isn't lazy enough). In fact, an example implementation is part of the tests for that pull request.
This can be generalized to the following Input
interpreter:
------------------------------------------------------------------------------
-- | Runs an 'Input' effect by running a monadic action after the 'Sem' has
-- completed, and then providing the result to each request recursively.
runInputFixSem :: forall i r a
. Member Fixpoint r
=> Sem r i
-> Sem (Input i ': r) a
-> Sem r a
runInputFixSem m sem = do
rec
a <- interpret (\Input -> pure i) sem
i <- m
return a
Such that:
runFinalState :: Members '[State s, Fixpoint] r
=> Sem (FinalState s ': r) a
-> Sem r a
runFinalState =
runInputFixSem get
. reinterpret (\GetFinal -> input)
Is runInputFixSem
worth adding to polysemy
or polysemy-zoo
?
whoa.
I'll take that as a "yes" 😄
I'll prepare a pull request for polysemy-zoo
. With perhaps some other Fixpoint
goodies...
how much easier would life be if there were only one repository?
I like polysemy-zoo
. Lower barrier to entry for newcomers to contribute, a good place to put stuff we're unsure of or is just straight-up crazy, and we're a little less stringent about avoiding additional dependencies here. Two "official" repos is a good thing to have, I feel.
Get the final value of a state effect.