Best Practices: Lists or Optional NonEmpty's?


#1

Not really a Dhall-specific question, but it’s come up in designing configs a fair amount and I’m curious about other people’s takes. Supposing for example you may or may not have say variants of a thing, do you prefer:

let Widget = { variants : List Text, .. }

or

let Widget = { variants : Optional (NonEmpty Text), .. }

(where NonEmpty a is something like { head : a, tail : List a }, obviously).

The latter strikes me as being perhaps more explicit about the absence of variants but is less ergonomic to work with.


#2

Another practice, used in dhall-kubernetes, is to use Optional (List a) so that you can define three states: null, [] or [x], and the dhall-to-json automatically omit attributes with None values.


#3

Definitely a great option for cases in which there is a fundamental difference between null and []; it’s just not immediately clear to me which is preferable for the case where there isn’t really a difference between null and [].


#4

If there isn’t a semantic difference between None (NonEmpty a) and [] : List a then my preference is to use List a as the representation