Scopes & Types

Computer languages generally have a recursive syntax which means that a program therein is logically like a tree. Since Algol a variable definition has pervaded one branch of the tree; the scope of a declaration was some sort of syntactic element, frequently nested. In most languages which let the programmer define new types, the scope of an identifier of a new type followed the same rules and limited to the same syntactic element.

In functional languages scope rules for value names (variables) are about the same but in the ML line of languages with type inference there are often no type declarations and the scope of a type name is a ‘module’. Many (all?) ML languages have ‘type variables’ like “'a” which appear in type expressions such as “'a -> 'a” which is the type of a function that returns the same type as its argument. Specs that I have found are silent on the scope of these special type variables. From the examples it would seem that the scope is some type expression that is not part of a larger type expression.

I think these details should be made clear. One must understand them.