When we have a type X
, we can calculate the number of inhabitants type X
has. IOW, the number of values that conform to that type.
If it's a primitive type, ie, if it doesn't depend on other types,
- eg for
Boolean
, we know, it has only two inhabitants,true
andfalse
and that's by definition in Boolean Algebra. If we know that a value is of type boolean, we know, that it iseither
true or false. - eg,
Int
, we know, it has infinite inhabitants, as there are infinite many integers.
If it's a type composed of other types, the question becomes, in what manners can we build a type, that's composed of other types?
A generic sum type. type sumtype = A | B | C Either[Int,String] type prodtype = A & B & C (Int,String) type X = Int & String has no inhabitants while type X = Tuple2(Boolean,Boolean) has 4 inhabitants.
A generic product type.