Trouble understanding local variable effects and their relationship to effect polymorphism #482
-
Suppose there is the following koka code:
The code defines two very similar functions, yet one doesn't compile, with the error
This is, to my understanding, because the mutability of the internal variable I fail, however, to understand how I'd appreciate help understanding this part. Furthermore, I also want to ask how precisely one could make a function of this sort, being polymorphic over effects, while disallowing the troublesome effects that cause this issue to happen. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
This is a solution:
As far as understanding the issue, it is more related to unification and inference and not that the I could give a stab at explaining the unification / type checking process, but I need to dig into it a bit more to understand myself why this happens. This is a common issue, and I wonder if there is something we could do to improve local var inference in particular. Anyways I hope the sample solution helps you in the meantime. Masking is also useful in general, when you come across an error like this. |
Beta Was this translation helpful? Give feedback.
This is a solution:
As far as understanding the issue, it is more related to unification and inference and not that the
trouble
function has access to the mutable state.I could give a stab at explaining the unification / type checking process, but I need to dig into it a bit more to understand myself why this happens. This is a common issue, and I wonder if there is something we could do to improve local var inference in particular. Anyways I hope the sample solu…