Comparison
Exhaustiveness checkingvsPattern matching
Exhaustiveness checking
you added a fifth case to the type and the build failed in nine places, which is exactly what you wanted.
A compiler check that every case of a closed type is handled, failing the build when one is missed. It is the mechanism that turns a sum type from documentation into a guarantee, and it is the single strongest argument for modelling states as types rather than as strings or flags. Without it, adding a case is a search; with it, the compiler produces the list.
Full entry →Pattern matching
one expression takes the value apart, names its pieces and picks a branch, all in the same line.
Branching on the shape of a value while simultaneously binding its parts. It is the natural way to consume an algebraic data type, and it is now in most mainstream languages in some form. Its practical advantage over a chain of type checks is that the compiler can see the whole set of cases, which is what makes exhaustiveness checking possible.
Full entry →