-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IndexedStateT has superfluous parts #4537
Comments
Shortly speaking, it's all about trampolining. A bit more details:
Also, you might want to dig into the original issue where there was quite a detailed discussion on that outer effect. It's better to have veterans answer this, but I may guess there wasn't an objective to have aligned implementation with the theory. In that sense, in cats could be found many other occurrences. |
I think it was 100% to improve stack safety. The outer For our State monad instance we use this except with F = Eval which is a somewhat optimized implementation of a free monad. |
The main issue I have is that while it is probably sound to use it for trampolining, any other effects in that outer F will be applied rather out of order, and you don't really have any laws locking you out of doing such at present, no? Would it make sense to introduce a base trampolining monad to use in that place instead rather than force everything through the entire underlying monad stack twice without using any of the other parts? e.g. error handling, etc. |
I think the first step might be to construct a law or test we think should pass and doesn't. From that concrete example we might have more ideas. We are under a few constraints:
If we were unconstrained by 1. we could make the constructor for the class private, so users could never observe the outer That said, I'm not sure how it being there harms anything. As to your point:
We definitely could have done another direct encoding I think, by using a Free structure here and running an interpreter on that in the end, but at this time point 2 from above will be an issue: that will almost certainly break binary compatibility now. I think withing our constraints (binary compatibility, stack safety and then performance, mostly in that order), we are open to making improvements. |
Digging into the definition of IndexedStateT we find
but that outer F isn't motivated by anything in the underlying theory.
is actual indexed state. The extra outer
F[_]
seems to have slipped in as a sort of Cayley-like construction, but it goes conspicuously unused, and if you attempt to use it to say slip another layer of F effects in during the glue-up of your computation, you'll violate laws left and right for non-commutative choices ofF[_]
. The inner F is motivated by the fact that you can distribute the (SA) => out of any F[] using strength, and (SB,) in using strength.Is there any documentation motivating/justifying this extra outer effect layer?
The text was updated successfully, but these errors were encountered: