3 ms·
The problem is, just like with "function", the usage word of the word "type" is a bit less formal in programming than mathematics. As far as I can tell, we use
by js8 7y ago
The problem is, just like with "function", the usage word of the word "type" is a bit less formal in programming than mathematics.
As far as I can tell, we use "types" in programming for 4 things:
1. Modelling the domain (e.g. type Temperature)
2. Limiting the range of values (e.g. enum)
3. Decision about how to store the data (e.g. ArrayList)
4. Specification of dispatch on values (e.g. file as an interface)
The formal type theory deals with 1 and perhaps a bit of 2. The original usage of types in programming (in old assemblers, Cobol, etc.) was 3. Dynamic programming languages primarily use the term in the 4th meaning.
- nbevans 7y agoYour #2 is wrong (sorry). Enums in most mainstream languages don't "limit"; they merely specify known values. Unknown values are still possible. For a type-safe enum, see discriminated union.
- thethirdone 7y agoCan you give some examples other than C, C++, and C# where this is true? Most languages either don't have them as definable types, are C based and therefore map them to integers, or actually limit values. AFAIK, python, java, rust, ocaml, haskell, and swift all have enums that actually limit values.
- t-writescode 7y agoYou can do bitwise operations in Java https://stackoverflow.com/questions/6282619/is-there-a-way-to-bitwise-or-enums-in-java https://stackoverflow.com/questions/6282619/is-there-a-way-t...