Closed world instances

From HaskellWiki

By default, Haskell type classes use the open world assumption:
It is possible to add instances for more and more types.
Sometimes you need a type class with a restricted set of instances,
that is, a closed world assumption.
If the set of instances is restricted then you can do a complete case analysis
of all types that inhabit the class.
The reverse is also true:
If you can do a complete case analysis on all instance types
then you have a restricted set of instances.
This is the key for declaring such a class.
We only declare one method, namely the method for doing a complete case analysis.

1 Method

As an example we use type-level natural numbers.
We want to define a class that only allows type-level natural numbers as instances.
Here it is:

2 Proofs

Since the set of class instances is restricted
we can conduct proofs about types that are instances of the class.
In the open world assumption it is not possible to conduct most proofs
since every statement could be invalidated by new class instances.
Here are some examples on commutativity and associativity: