I don't know how this would be expressed in the type system, but here goes:
What if we had &0, &1, etc as functions that set fields in tuples?
(1, 2, 3) |> &0 3 would be (3, 2, 3)
We have .field and &field syntax for records, but only .0 syntax for tuples, so it feels like adding this feature could fill that hole in the language. Also this would make it easier to modify large tuples (think matrix types) which there's no syntax for currently.
Type of &0: (a)b, a -> (a)b
Type of &1: (a, b)c, b -> (a, b)c
It should be possible to express in the type system (although it could potentially have a lot of type parameters!)
Did we ever add this feature for records? I think we should only consider this if it is already a record feature.
We did, https://github.com/roc-lang/roc/pull/7002
Oh cool. Missed that
I'm currently neutral to the feature, but seems reasonable.
The main reason I like the idea is because it's orthogonal to our existing features
I'm struggling to think up possible real-world uses of this; do you have some in mind?
for the same reason https://github.com/roc-lang/roc/pull/7002 exists: say you have an application state which is a tuple of 3 parts, and you want to pass a function that can set, say, the third state part. this would let you write &2 instead of having to write \(x, y, _), n -> (x, y, n). it would match the tuple getter of .2 and be consistent with the record syntax.
assuming an app design like https://docs.google.com/document/d/16qY4NGVOHu8mvInVD-ddTajZYSsFvFBvQON_hmyHGfo/edit#heading=h.5gvhiqd8pauk
Last updated: Jun 16 2026 at 16:19 UTC