Stream: contributing

Topic: More standard library purity inference


view this post on Zulip Brendan Hansknecht (Dec 28 2024 at 19:37):

What functions should we be duplicating and adding ! versions of for now. For example List.map! and List.walk!. The code in #beginners > Handling List.walk Result Bool is an example where we need a second version of the function. Otherwise the end users always has to manually write a recursive function.

view this post on Zulip Brendan Hansknecht (Dec 28 2024 at 19:37):

I get that eventually for loops will deal with some of these use cases, but for loops may not come for quite a while, so a solution that can be used now seems beneficial.

view this post on Zulip Richard Feldman (Dec 28 2024 at 20:19):

walk! for sure

view this post on Zulip Richard Feldman (Dec 28 2024 at 20:19):

I'd like to hold off on map! until we've seen some use cases where it's desirable over for_each!

view this post on Zulip Sam Mohr (Dec 28 2024 at 21:03):

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

view this post on Zulip Sam Mohr (Dec 28 2024 at 21:03):

For List.walk!

view this post on Zulip Sam Mohr (Dec 28 2024 at 21:04):

Someone can pick it up first, but it's a pretty good beginner issue

view this post on Zulip Yunti (Dec 28 2024 at 22:31):

Completely new to roc - Does the purity inference work mean that we’ll need a pretty much duplicate stlib? One effectful one pure?

view this post on Zulip Sam Mohr (Dec 28 2024 at 22:33):

Just for the functions we want to have potentially effectful, but yes.

view this post on Zulip Anthony Bullard (Dec 28 2024 at 22:34):

I don't think so. Most of the functions that need callbacks that would need to also have effects executed are things like walk and map (and for_each! now). And many of them will be used little after the introduction of for

view this post on Zulip Sam Mohr (Dec 28 2024 at 22:40):

@Yunti We discussed having effectfulness variables that would allow both in the same function. For example:

List.map : List a, (a -fx-> b) -fx-> List b
List.map = \items, mapper -> ...

If mapper was effectful, then List.map would become effectful, and same if mapper was pure. This could help mitigate the problem that ecosystems tend to split into a pure set of functions and a copied set of effectful functions. The problem here was that we now had to expose a lot of complexity that people would need to somewhat understand before using basic parts of Roc.

We decided that if we could get away without that feature, we'd probably be fine. Luckily, with the addition of for loops and var and other Coming Soon features, we won't have need for very many builtins that are effectful, as Anthony said.

view this post on Zulip Yunti (Dec 30 2024 at 09:32):

@Sam Mohr Thanks for your reply (and Anthony). Are effectfulness variables essentially polymorphic variables with regard to effects? Would those have hidden the clear difference in the type signature (ie thin vs fat arrows)? Possibly getting off topic now from the original topic.

view this post on Zulip Sam Mohr (Dec 30 2024 at 17:24):

That's what they are, yes. Roc only has the concept of pure or not pure, we don't have specific effects. So each of those variables would just be an on-off switch.

view this post on Zulip Sam Mohr (Dec 30 2024 at 17:26):

We also used to have ! as an operator that would mark effect use, but that's no longer necessary since we just made it part of the function name

view this post on Zulip Sam Mohr (Dec 30 2024 at 17:27):

We'd probably have to change that back to support effectfulness variables, which is another point against adding them

view this post on Zulip Sam Mohr (Dec 30 2024 at 17:27):

Since just having ! as part of a function's name is really simple

view this post on Zulip Ian McLerran (Dec 30 2024 at 19:18):

Working on List.walk!, and just want to double check I have the desired signature:

walk! : List elem, state, (state, elem => state) => state

view this post on Zulip Anthony Bullard (Dec 30 2024 at 19:19):

That looks right to me


Last updated: Jul 06 2025 at 12:14 UTC