Domain Types are a way of constraining an existing type to a particular set of values. Consider a US zip code. It’s 5 characters, where each character is a numerical digit. Two common ways to declare this type are:
- a class that has a string member with the data
- a type definition that declares ZipCode to be synonymous with String
Leema is takes an approach similar to #2, but different in that the ZipCode is synonymous with String, but a String is not synonymous with ZipCode. Once you have a ZipCode, you can pass it to any function that takes a String, but if you have a String, you cannot pass it to a function that takes a ZipCode without first converting it.