Could someone please explain clearly and succinctly the concepts of language type systems?
I’ve read a post or two here on type systems, but have trouble finding one that answers all my questions below.
I’ve heard/read that there are 3 type categorizations: dynamic vs static, strong vs weak, safe vs unsafe.
Some questions:
- Are there any others?
- What do each of these mean?
- If a language allows you to change the type of a variable in runtime (e.g. a variable that used to store an int is later used to store a string), what category does that fall in?
- How does Python fit into each of these categories?
- Is there anything else I should know about type systems?
Thanks very much!
1) Apparently, there are others: http://en.wikipedia.org/wiki/Type_system
2)
Dynamic=> Type checking is done during runtime (program execution) e.g. Python.Static(as opposed to Dynamic) => Type checking is done during compile time e.g. C++Strong=> Once the type system decides that a particular object is of a type, it doesn’t allow it to be used as another type. e.g. PythonWeak(as opposed to Strong) => The type system allows objects types to change. e.g. perl lets you read a number as a string, then use it again as a numberType safety=> I can only best describe with a ‘C’ statement like:mallocreturns a (void *) and we simply type-cast it to (int *). At compile time there is no check that the pointer returned by the function malloc will actually be the size of an integer => Some C operations aren’t type safe.I am told that some ‘purely functional’ languages are inherently type safe, but I do not know any of these languages. I think Standard ML or Haskell would be type safe.
3) “If a language allows you to change the type of a variable in runtime (e.g. a variable that used to store an int is later used to store a string), what category does that fall in?”:
This may be dynamic – variables are untyped, values may carry implicit or explicit type information; alternatively, the type system may be able to cope with variables that change type, and be a static type system.
4) Python: It’s dynamically and strongly typed. Type safety is something I don’t know python (and type safety itself) enough to say anything about.
5) “Is there anything else I should know about type systems?”: Maybe read the book @BasileStarynkevitch suggests?