New notation for records?

Eh, if type families weren’t slow as molasses something like get @"foo.bar.baz" could be assembed out of accessors for "foo", "bar" and "baz" separately. At that point the separator can be any character and the language doesn’t need a syntax extension.

This would then be extendable to the FFI land too: offset into a C struct works completely differently under the hood, but ultimately means the same thing.


From what I gather, it precisely mirrors what the resulting program does: for every record you update you produce a new record with one differing field.

Over the years there have been a lot of discussions about how Haskell needs convenient record notation (implemented a decade ago, of course). I however find the entire idea of nested record updates to be at odds with functional programming as a whole. The argument goes roughly like: if I want to update foo.bar.baz directly and it’s by design safe to do so relative to the rest of foo, why don’t I just have baz separately (or at the same level as foo)? Repeat the thought experiment until you no longer need nested record updates.

5 Likes