Well that was entirely predictable; as I said last time, if you ask ten developers for a definition of "type", you get ten different answers. The comments to the previous article make for fascinating reading! Here's my attempt at describing what "type" means to me as a compiler writer. I want to start by considering just the question of what a type is and not confuse that with how it is used.Fundamentally, a type in C# is a mathematical entity that obeys certain algebraic rules, just as natural numbers, complex numbers, quaternions, matrices, sets, sequences, and so on, are mathematical entities that obey certain algebraic rules. By way of analogy, I want to digress for a moment and ask the question "what is a natural number?" That is, what fundamentally characterizes the numbers 0, 1, 2, 3, ... that we use to describe the positions of items in a sequence and the sizes of everyday collections of things? This question has received a lot of attention over the centuries; the definitive answer that we still use today was created by Giuseppe Peano in the 19th century. Peano said that a natural number is defined as follows: Zero is a natural number.
Every natural number has a "successor" natural number associated with it.
No natural number has zero as its successor.
Unequal natural numbers always have unequal successors.
If you start from zero, take its successor, and then take the successor of that, and so on, you will eventually encounter every natural number. (*)Surprisingly, that's all you need. Any mathematical entity that satisfies those postulates is usable as a natural number. (**) Notice that there's nothing in there whatsoever about adding natural numbers together, or subtracting, multiplying, dividing, taking exponents, and so on. All of those things can be bolted on as necessary. For example, we can say that addition is defined as follows: (n + 0) = n
(n + (successor of m)) = ((successor of n) + m)
Read more: Fabulous Adventures In Coding
QR:
Every natural number has a "successor" natural number associated with it.
No natural number has zero as its successor.
Unequal natural numbers always have unequal successors.
If you start from zero, take its successor, and then take the successor of that, and so on, you will eventually encounter every natural number. (*)Surprisingly, that's all you need. Any mathematical entity that satisfies those postulates is usable as a natural number. (**) Notice that there's nothing in there whatsoever about adding natural numbers together, or subtracting, multiplying, dividing, taking exponents, and so on. All of those things can be bolted on as necessary. For example, we can say that addition is defined as follows: (n + 0) = n
(n + (successor of m)) = ((successor of n) + m)
Read more: Fabulous Adventures In Coding
QR:
0 comments:
Post a Comment