Replies: 1 comment 7 replies
-
|
It doesn't answer your question about local, but I would probably use a non-mutable variable for this. fun for<a, item, cb-fx>(
iterator: a,
next: a -> <div,console|cb-fx> maybe<item>,
cb: (item) -> <ctl-flow,div,console|cb-fx>()
): <div,console|cb-fx>()
match iterator.next()
Nothing ->
()
Just(item) ->
val result =
handle({cb(item); True})
ctl continue_()
println(" in continue handler")
True
ctl break_()
println(" in break handler")
False
if result then
println(" recursing")
for(iterator, next, cb)
else ()As far as using a mutable variable what you want to do is actually mask the local: Just(item) ->
var recurse := True
handle ({ cb(item) })
ctl continue_()
println(" in continue handler")
()
ctl break_()
println(" in break handler")
recurse := False
()
println(" recursing")
if recurse then
mask<local>{for(iterator, next, cb)}By masking the local you are telling the recursive call that it doesn't need to know about the handler for the local variable, even though you needed it to make a decision in the if expression. Otherwise it thinks that the recursive call needs access to the local above it in the stack and then because of the recursion it would be able to see all local variables recursively above it in the stack, not to mention you would need a local variable just to call the for expression in the first place. That is why you get two locals. You are basically unrolling the handler stack in the type, which turns out to be impossible because of recursion. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
This program is not right (
breakeffect is not handled properly), but it type checks.To fix the
breakeffect handling I introduce a local variable:Which fails to type check, apparently this uses an effect called
localnow. I can't find any documentation on it, but from the definition of it in the standard library it looks identical to Haskell's ST. So I add it to the type sig:But it fails with:
How can
local<$h>appear twice in an effect type?Beta Was this translation helpful? Give feedback.
All reactions