Skip to content

Trouble understanding local variable effects and their relationship to effect polymorphism #482

Answered by TimWhiting
AZMCode asked this question in Q&A
Discussion options

You must be logged in to vote

This is a solution:

pub fun local-inferred<e>(trouble: () -> e ()): e list<int>
  var out := []
  for(0,10) fn(i)
    mask<local>{trouble()}
    out := Cons(i,out)
  out

fun main()
  val x = local-inferred() fn()
    "Hi".println
  x.show.println

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…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@AZMCode
Comment options

Answer selected by AZMCode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants