Is there syntax to do something like that
inst1 = { one : 1 , two :2 }
{inst1 & three : 3} # this does not work, I want copy of inst1 and additional field, regardless of what inst1 holds (in my case it not so easy to know that)
No. Roc's type system doesn't allow that. The &
operator expects the argument and result records to have the same type, and that means they must have the same fields. That's how records are defined.
A Dict would be the appropriate structure for what you're trying to do. The values all must have the same type. If you have values of different types you can put them in a tagged union.
This stuff can feel restrictive if you're used to dynamic languages but the restrictions tend to guide you towards fast and reliable code.
what is tagged union ?? Ok I see there is chapter for that, maybe I will figure this out
Last updated: Jul 06 2025 at 12:14 UTC