Briefly: atd, Cap n' Proto, Protobuf and many others occupy the role of representing the same datatype in different languages and transmitting values of that datatype across the wire and/or persisting in storage. But I'm finding most programs have a need for multiple variations to that core record datatype. For example, when you persist an OCaml/Java/etc record datatype to a database, you don't use the OCaml/Java/etc record datatype. You use the data types provided by the database (VARCHAR, BLOB, etc). You can adopt an ORM solution, use an object database, or write a pair of type-conversion functions from OCaml/Java/etc to your database datatype. That is one example of a "variation" that you must spend engineering time on.
I mentioned in the article that my user needed 5 different variations. For example, with the sqlite3 database they were using, the database table variation required writing a pair of datatype-conversion functions to and from the sqlite3 database. What if there was a way where we could write these datatype-conversion functions in one place (cough cough: OCaml with a line-by-line semantics preserving feature) and have bindings to/from the database, the view layer, the controller and all the other variations generated in the appropriate Java/Swift/SQL/etc languages? And what if we could deploy modifications to that datatype (ex. adding a database field) in the same uniform way we do all other minor variations to a datatype? That is the "drastic QOL (quality of life) improvement" win my users asked for.
That QOL win deserves its own article. Yes, I'll post it when done.
If you mean propagating changes to a schema across all layers of the stack, that may not necessarily be a good idea. In my experience we want to keep the datatype definitions at different layers somewhat independent of each other, to allow evolving separately. For example, the database table could have a `more JSON` column to allow adding data that was not foreseen in the original table design; but the application's datatype would decode that JSON into specific fields to show the user perhaps.
[%%compactexpr
"SumArStaged";
[ arr; n ];
let sum = ref 0 in
for i = 0 to 3 do
for j = i to min (i + 3) (n - 1) do
sum := !sum + arr.(j)
done
done;
!sum]
;;
print_c "sum_ar" (module SumArConv) SumArStaged.expr;;
So that has the exact indent level of the C code. (Details: The above is formatted using the "conventional" profile for the "ocamlformat" tool)Of course, there is a disadvantage. I had to use global variables in the above "compactexpr". Global variables mimic the C language (ie. C functions are globally-scoped or file-scoped functions) but wouldn't be a good fit when translating that code to functional languages. Additionally, the OCaml idiom `fun arr n ->` was lost, but that seems minor.
Do you and others find the above readable? (If so, perhaps it would be best to give some flexibility for the coding style.)