Thomas user said in the comment:
I think modelling the world in terms of "or" (aka discriminated union) and "and" (aka records) is a very powerful functional trick. Sometimes, functions/interfaces are useful too, but if I tend to stick to "or"/"and" as much as I can :-)
Suppose I'm modelling the world of Animal
(open-world assumption), how could I do it by using discriminated unions, records and sometimes functions/interfaces?
For example, with animal types, can I use discriminated union to classify them?
type Type =
| Phyla of Phyla
| Chordata of Chordata
| Arthropods of Arthropods
| ...
and Chordata =
| Fish
| Reptiles
| Mammals
| ...
Chordata
should not need to refer toType
in any way. So you should write the definition ofChordata
first, then the definition ofType
, and that lets you avoid having anyand
keywords. The presence ofand
in your data model definition is usually a code smell: it is sometimes necessary, but it often means that you don't yet have a good representation of the domain. – rmunn