I'm wondering if we should add this to builtins somewhere. This came up while upgrading an app that used Task.loop
loop! : state, (state => Result [Step state, Done done] err) => Result done err
loop! = \state, fn! ->
when fn! state is
Err err -> Err err
Ok (Done done) -> Ok done
Ok (Step next) -> loop! next fn!
seems reasonable!
I feel like I would just use recursion instead
So it was something we needed when we had Task but now we don't?
I thought there was some magic that Task.loop had that prevented alias analysis issues.
Yeah, using recursion with Task is a little less intuitive, so Task.loop makes sense
but I’m not sure it adds much in the purity inference world
If you want, you can share the example and we can compare
Yeah, I think you're probably right. I was just translating the basic-cli examples.
I think now is a good time to revisit these and "modernise" them. They were written using the API's we had at the time, but a lot has changed.
Even just going through my AoC examples, roc today feels like a world away from last year.
Last updated: Jun 16 2026 at 16:19 UTC