What is a type? You see that word used all the time in computer languages but it never seems to be precisely defined. Here is my definition:
A type is a set of bits together with the operations that can be performed on those bits along with the rules the operations satisfy.
This is really just math 101 but the computer science world is finally catching up. Math doesn’t mention the set of bits because everything is a set in math.
An int is a set of bits (usually 32 or 64 these days) that can be added, subtracted, multiplied, divided, complemented, etc. These operations satisfy certain rules. For example, x + y = y + x. They actually satisfy a long list of rules that most people can’t be bothered to learn until something blows up. What about 2’s complement or unsigned ints or overflow? Ain’t nobody got time for that.
As my friend Candy Chiu first pointed out to me, C++ concepts (at the time called Concepts Lite) provide a language mechanism to do precisely this. More precisely, they allow compile time checks on boolean constraints on template parameters. And template parameters are types.