Stream: ideas

Topic: Record update syntax


view this post on Zulip Joshua Warner (Nov 24 2022 at 05:02):

Working on the parser, one thing that I've noticed that feels a little _out of place_ is the record update syntax - e.g. {old_record & new_field1: "a", new_field2: "b"}. Right now this is the only collection-like thing that can't use collection_trailing_sep_e, because of that old_record & bit.

And FWIW, it seems strange to me that this isn't just an operator between records - e.g. old_record & {new_field1: "a", new_field2: "b"}. It doesn't necessarily have to be a first-class operator (yet; tho that could be interesting) - e.g. old_record & new_fields would give a syntax error.

Thoughts?

view this post on Zulip Brian Carroll (Nov 24 2022 at 05:34):

All operators are really just aliases for functions. That's how they're implemented. + is really Num.add. The functions all have types.
What is the type of this function?

view this post on Zulip Joshua Warner (Nov 24 2022 at 05:36):

I'm suggesting this only happens at the syntax level... for now.

view this post on Zulip Joshua Warner (Nov 24 2022 at 05:37):

In the future tho, it's not crazy to imagine this having a type like:

& : {}a, {}b -> {}(a+b)

view this post on Zulip Joshua Warner (Nov 24 2022 at 05:37):

(where a+b automatically implies the constraint that those sets of fields are distinct)


Last updated: Jun 16 2026 at 16:19 UTC