> If you have a set of key value pairs where all the values are the same, you can use a Map or HashMap. These are both easily serialisable.
This is ultimately the choice most people suggested back then, but I have two issues with it:
1. It leads to a ton of boilerplate, first in the step that converts the request record to a map, then adding stuff to the map and then serializing it. Instead, consider what just adding a field to what you know is a record is in F#:
let newRecord = {| oldRecord with token = token |}
This is vey close to the spread syntax of JS, and is super intuitive and elegant to write.
2. You lose type safety: say your JSON object has a bunch of things of different types within it, like a record with a few records or arrays inside. If you want to convert that to a map, you effectively have to make it a Dictionary<string, obj>, or whatever the Haskell equivalent for obj would be (obj is the "base class" in F#: everything is an obj.) That means you completely lose type information from that point on.
The closest any functional language gets to what I would consider "ideal" in this scenario is ReScript, which allows you to type row polymorphic open objects and use JS-like syntax to work with them. This is in addition to good ol' records, of course. Reason is pretty good, in this aspect, too.
The closest any functional language gets to this