Stream: beginners

Topic: self-reference in closure not allowed


view this post on Zulip Gabriel Pickl (Oct 10 2022 at 21:09):

I'm a bit confused why

run2 =
    res <- await Stdin.line
    _ <- await Stdout.line res
    run2

is not allowed. I know simple self-reference in eagerly evaluated languages doesn't work, but here the evaluation should only happen once the closure after Stdin.line gets called? This is resolvable by giving run2 an empty argument, but feels kind of strange.

view this post on Zulip Ayaz Hafiz (Oct 10 2022 at 21:16):

Yeah, I think that might just be an oversight. We do a syntactic check to see if something looks like a function, and if not and it's self-recursive, you get that error

view this post on Zulip Ayaz Hafiz (Oct 10 2022 at 21:16):

But in this case this is fine

view this post on Zulip Richard Feldman (Oct 10 2022 at 21:25):

@Gabriel Pickl can you open an issue for this?

view this post on Zulip Gabriel Pickl (Oct 10 2022 at 21:31):

sure

view this post on Zulip Gabriel Pickl (Oct 10 2022 at 21:31):

as a detail though: writing this without the backpassing syntactic sugar seems to result in the same error

view this post on Zulip Gabriel Pickl (Oct 10 2022 at 21:37):

https://github.com/roc-lang/roc/issues/4291

view this post on Zulip Richard Feldman (Oct 10 2022 at 21:38):

yep, that makes sense! Backpassing is just syntax sugar, and this error happens after desugaring


Last updated: Jul 05 2025 at 12:14 UTC