Stream: ideas

Topic: purity-inference `loop!`


view this post on Zulip Luke Boswell (Nov 08 2024 at 02:23):

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!

view this post on Zulip Richard Feldman (Nov 08 2024 at 02:58):

seems reasonable!

view this post on Zulip Agus Zubiaga (Nov 08 2024 at 03:18):

I feel like I would just use recursion instead

view this post on Zulip Luke Boswell (Nov 08 2024 at 03:19):

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.

view this post on Zulip Agus Zubiaga (Nov 08 2024 at 03:22):

Yeah, using recursion with Task is a little less intuitive, so Task.loop makes sense

view this post on Zulip Agus Zubiaga (Nov 08 2024 at 03:23):

but I’m not sure it adds much in the purity inference world

view this post on Zulip Agus Zubiaga (Nov 08 2024 at 03:23):

If you want, you can share the example and we can compare

view this post on Zulip Luke Boswell (Nov 08 2024 at 03:25):

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