Reproducing the behavior
This excerpt:
def main():
with IO:
x <- wrap(1)
return wrap(wrap(2))
Should be desugaring to
(main) = (IO/bind (IO/wrap 1) λa (a λ* (IO/wrap (IO/wrap 2))))
Instead it desugars into
(main) = (IO/bind (IO/wrap 1) λa (a λb let {c d} = b; λ* (c (d 2)) IO/wrap))
wrap is seen as a free variable, so it gets applied in a deferred way as well as duplicated if it's used more than once.
We need to first substitute the wrap and only then desugar the bind.
System Settings
Bend commit 270f39c
Additional context
No response
Reproducing the behavior
This excerpt:
Should be desugaring to
Instead it desugars into
wrapis seen as a free variable, so it gets applied in a deferred way as well as duplicated if it's used more than once.We need to first substitute the
wrapand only then desugar the bind.System Settings
Bend commit 270f39c
Additional context
No response