I wonder if we should have a "pipe and assign" operator, so instead of:
files_ = files_ |> Dict.insert path sha
you can do something like:
files_ |= Dict.insert path sha
and probably += et al.
I totally agree that *-assign operators would be nice. I think we should have a separate discussion on those? Wouldn't want to block this feature on those
3 messages were moved here from #ideas > for and var by Agus Zubiaga.
I really like that |= Dict.insert ... is almost as concise as the usual style in imperative languages where Dict.insert would mutate the dict itself, but without the characteristics we don't like about that
(the reassignment happens at the call site, so it's easy to spot)
Yes, among the operators that this would introduce, the |= would probably be far be the best addition
It seems like a pipe assign plus math assigns are a good start:
Definitely think we shouldn't go for ++ and -- operators, they lead to confusion about when the incrementation happens
I think an assignment wouldn’t be an expression in Roc, so it wouldn’t work anyway, but I agree we don’t need them
I'm not sure about %= and ^=. You get a different sort of number out. Like, length *= 2 still gives you a length, but length ^= 2 would give an area, you'd more likely write area = length ^ 2. They're rare enough that I think it'd be fine and not frustrating to have to write them out with =. If we skip them, that's 2 fewer weird operators.
Is ^ power? I assumed it was bitwise xor
I think %= can be quite useful in general for numbers limited to a specific modulo for mathematic purposes
I personally am not sure I like |= compared to being explicit.
But it probably is reasonable
Brendan Hansknecht said:
Is
^power? I assumed it was bitwise xor
In some languages (haskell is one I can think of right now) it is power. Also in mathematical formulas written in ascii, power is often denoted with it (see latex for example). In programming however I have seen ^ mostly for bitwise xor as well. I think ** is used more often for power, like in python (and for some reason also in haskell)
Instead of a new operator, what about just inferring that the left-hand-side is also the first pipeline component when not specified, i.e. the following would be equivalent:
a = a |> f |> g
a = |> f |> g
maybe it'd be formatted as =|> but it doesn't need to actually be a combined operator
Last updated: Jun 16 2026 at 16:19 UTC