Do dynamic/static languages associate types or classes to values or variables? In Practical Foundation of Programming Languages by Harper


  There have been many attempts by advocates of dynamic typing to
  distinguish dynamic from static languages. It is useful to consider
  the supposed distinctions from the present viewpoint.
  
  
  Dynamic languages associate types with values, whereas static languages associate
  types to variables. Dynamic languages associate classes, not types, to values by tagging them with identiﬁers such as num and
  fun. This form of classiﬁcation amounts to a use of recursive sum
  types within a statically typed language, and hence cannot be seen as
  a distinguishing feature of dynamic languages. Moreover, static
  languages assign types to expressions, not just variables. Because
  dynamic languages are just particular static languages (with a single
  type), the same can be said of dynamic languages.
  Dynamic languages check types at run-time, whereas static language check types at compile time. Dynamic languages are just as surely
  statically typed as static languages, albeit for a degenerate type
  system with only one type. As we have seen, dynamic languages do
  perform class checks at run-time, but so too do static languages that
  admit sum types. The difference is only the extent to which we must
  use classiﬁcation: always in a dynamic language, only as necessary in
  a static language.
  


What do the first two sentences in the first part try to say: 


What do dynamic languages associate  with values: types or classes or both?
What is the significance of associating types or classes to values or variables? Do static languages associate types to variables but not to values? Do dynamic languages associate types or classes to variables besides values?


Thanks.
In those bullets, Harper is addressing common misconceptions about static versus dynamic typing. Each of those bullet points starts with a misconception, and then continues with Harper's clarification.

So, the first misconception is:


  Dynamic languages associate types with values, whereas static languages associate types to variables.


Harper disagrees, and instead says that dynamic languages associate classes to values. This comes from a type-theoretic perspective, where it is useful to reserve the notion of a "type" to a particular form of static classification of expressions. In the textbook, Harper defends this perspective by demonstrating that "dynamic types" and "static types" can coexist, and in this way, the two concepts are orthogonal. In particular, there is a special static type which Harper calls dyn, and values of type dyn are given a tag at runtime which identifies their class, i.e. their "dynamic type". (By the way, it's worth mentioning that this tagging mechanism is exactly how dynamic types are implemented in modern languages.) In dynamically typed languages, it is often the case that the static types do not carry very much information, for example all expressions might actually have the static type dyn.

The interest in "values versus variables" comes from the "dynamic versus static" perspective on types. If we associate "types" with values, then we can only determine their "type" at runtime. But if we associate types with variables, then we can determine the type of the variable statically. Harper is just trying to point out that there doesn't need to be an issue of "this versus that": dynamic types and static types do not lie on the same spectrum. Simply put, from the perspective of type theory, "dynamic types" are not types.

To sum up, if we take a type-theoretic perspective and make a distinction between types and classes, then we can make this statement: all languages associate types with both variables and values. In fact, we can make an even stronger statement, which is this: all languages associate types with expressions. Variables and values are just two different forms of expressions.