Closed KingoftheHomeless closed 5 years ago
Oh! This hasn't been updated to use the changed names for Yo
(since polysemy-zoo is still based on the old version). Perhaps we should resolve that before merging in?
Alright, I've now added a slew of uses of Final
.
Now I'll write some tests and see how everything works.
From what I can tell, -Final
interpreters act exactly like the kind of interpreters that take explicit lowering actions, such as runAsyncInIO
and runErrorInIO
, only are more flexible, as they work through weavings, which can be provided by Sem
implicitly, rather than straight-up natural transformations.
The difference is that you can place -Final
interpreters anywhere, whereas interpreters with explicit lowering functions need to run after return-value changing effects in order to be composed using .@
.
You could actually place such interpreters before return-value changing interpreters by providing an explicit lowering function based upon the interpreter chain, using fmap
and the like to massage the interpreter chain into a natural transformation. In this case, these interpreters will exhibit the same strange semantics as -Final
interpreters (as effects that care about state semantics typically have return-value changing interpreters.)
Final
, in a sense, makes it a bit "too easy" to do that kind of evil interpreter chaining, but has a much better UX. Providing lowering functions is very verbose, and working with .@
is rather finicky. Because of that, I'd like for Final
to eventually become part of Polysemy proper, but at the moment, it can live here.
By the way, the tests in FinalIOSpec
(edit: now a part of FinalSpec
) work through IO
in order to test how -Final
interpreters work within it. Is that OK with you?
Let me know when this is ready for me to take a look!
It's ready now; I've added tests. Although, I do need to update this to use the new name for Yo
. I'd wait until #36 is resolved before merging this in, as in resolving that issue we will work out how to properly update polysemy-zoo.
Perhaps you want me to ping you? @isovector
"It's ready", I say, as I notice "hey we can do stuff with resource too".
Blegh. Behaviour of runResourceFinal
is very straight-forward, and works just like runResourceInIO
.
Rebasing is a nefarious beast. Anyway, what's your opinion on merging this, @isovector ?
We still have the unresolved question on whether or not we should remove runFinalLift
and runFinalLiftIO
.
I'll merge anything that's green into the zoo! Here be dragons!
Then let's do it.
This is the
Lift'
/Final
effect originally discussed at https://github.com/polysemy-research/polysemy/issues/163, but touched up, and with the introduction of aTactics
-like environment to make it easier to write interpreters using it.I'm going to soon add a few more modules to showcase how this can be used, but you should be able to get the gist from
Polysemy.Final