Base types vs compound types
In any language there are based types, such as int, bool, unit, char. We can then use these in nested compound types, such as tuples, lists, and options.
For any programming language, there are 3 fundamental type building-blocks:
- “Each of”: a
tvalue contains values of each oft1 t2 ... tn- The entire idea is to build a new tyoe
twhere the values ofthave each of some other collection of types.
- The entire idea is to build a new tyoe
- “Self Reference”: a
tvalue can refer to othertvalues- with each of and one of we cannot build types like lists, since those are recursive as each value contains a list that is smaller.
- “One of”: a
tvalue contains values of one oft1 t2 ... tn- A value contains one of the values from a collection of distinct types
Examples
- Tuples build each-of types
int * boolcontains anintand abool
- Option build one-of types
int optioncontains anintor it contains no data
- Lists use all three building blocks
int listcontains anintand anotherint listor it contains no data
Note how each of the building blocks can be associated with and, or, or recursion.