Nick
Nick

Reputation: 5430

Is static typing a subset of dynamic typing?

I was going to add this as a comment to my previous question about type theory, but I felt it probably deserved its own exposition:

If you have a dynamic typing system and you add a "type" member to each object and verify that this "type" is a specific value before executing a function on the object, how is this different than static typing? (Other than the fact that it is run-time instead of compile-time).

Upvotes: 1

Views: 231

Answers (2)

Andreas Rossberg
Andreas Rossberg

Reputation: 36098

Technically, it actually is the other way round: a "dynamically typed" language is a special case of a statically typed language, namely one with only a single type (in the mathematical sense). That at least is the view point of many in the type systems community.

Edit regarding static vs dynamic checking: only local properties can be checked dynamically, whereas properties that require some kind of global knowledge cannot. Think of properties such as something being unique, something not being aliased, a computation being free of race conditions. A suitable static type system can verify such properties, because it has the ability to establish certain invariants on the context of the expression that is being checked.

Upvotes: 9

static typing happens at compile-time, not at run-time! And that difference is essential!!

See B.Pierce's book Types and Programming Languages for more.

Upvotes: -2

Related Questions