If we provide we can now add a label to each value and thus get the desired anonymous records described earlier.
First, all your logic will run in some kind of environment that provides logging, configuration, other external data such as templates and/or some global application state.
This environment must be managed somehow and correctly be passed to the specific logic.
Some of these problems can partially be resolved similar to the type classes and implement instances for our request/response types, but it does not solve the problem of defining many types and writing many similar JSON parsers/serializers and comes with the drawbacks mentioned above.
One way to solve these problems can be via anonymous records. An anonymous record is similar to a The big advantage here is that we do not need to introduce any new data types or type classes, we can simply write down what dependencies or functions actually have, and then after combining them or when testing them providing just what they need.
For example: record and read/write fields as needed when converting to/from business logic types, while automatically having the JSON parsing/serialization taken care of.
There’s even an interesting library in the works by Denis Redozubov that could one day provide automatic migrations on top of that.
This idea is pretty decent, but it also has some drawbacks: How do we express nested constraints? The result is lot’s of type classes and we start to loose track of what happens again.
Another drawback is that we now can construct smaller environments for testing (or reuse sites), but we still need to introduce new types and write type class instances for every smaller bit.
Secondly, you will need to read and write out data into the real world, for example, to talk to a JSON REST-API.
Let’s take a look in detail at these problems and how we can solve them today.
Once the tool is built, you can reuse it to quickly update your data.