paris-branch / dancelor

A chancelor for Scottish country dance musicians
https://dancelor.org
0 stars 0 forks source link

Handle default parameters in a cleaner way #265

Closed Niols closed 8 months ago

Niols commented 9 months ago

Parameters are annoying because there are two ways to look at them. When we process them at the end, each parameter should have a value. However, when we set them in an interface, we want to only change a bunch of them. Basically, there are parameters and parameter diffs or something.

Anyhow; the current version decided to have a type VersionParameters.t (and same for sets and books) which is a record of options. None means “do not update” and “Some” means “replace by” (except for transpositions but OK). Then we provide a value VersionParameters.default that has all its fields to Some and a bunch of getters that assume that they work on a Some. This works but isn't very type-safe. A way to provide this in a type-safe way would be to actually have parameters and parameter diffs; and the former would not contain the options. One could imagine a PPX providing that but I don't know of one, and it is a bit heavy to provide manually.

Instead, this PR decides to give up on VersionParameters.default but to provide normal getters (returning an option) and fancy getters (returning a value, defaulting on something if need be). I think this is a good compromise. I use the opportunity to clean up a tiny bit. WDYT @R1kM?