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.
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.
walk!
for sure
I'd like to hold off on map!
until we've seen some use cases where it's desirable over for_each!
https://github.com/roc-lang/roc/issues/7425
For List.walk!
Someone can pick it up first, but it's a pretty good beginner issue
Completely new to roc - Does the purity inference work mean that we’ll need a pretty much duplicate stlib? One effectful one pure?
Just for the functions we want to have potentially effectful, but yes.
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
@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.
@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.
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.
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
We'd probably have to change that back to support effectfulness variables, which is another point against adding them
Since just having ! as part of a function's name is really simple
Working on List.walk!
, and just want to double check I have the desired signature:
walk! : List elem, state, (state, elem => state) => state
That looks right to me
Last updated: Jul 06 2025 at 12:14 UTC