Jalada home about archive

More on Scoping. Type Checking

29th January 2010 (Absent)

These are lecture notes from my Computer Science course, not a general reference for "More on Scoping. Type Checking"

An identifier (e.g. +) has several meanings depending on the type at which it is used (polymorphic?). The entry in the symbol table for this identifier must contain attribute records for all meanings in the scope.

Dynamic Scoping

In previous lectures we have discussed static (otherwise known as lexical) scoping, which is where the scope of a declaration is determined by the physical structure of the program.

However, some languages support dynamic scoping which is where the scope of a declaration is determined by the control flow (current declaration is last declaration encountered during execution). Based on the slides it sounds like this isn’t a great idea as it makes programs hard to understand. But is ‘sometimes useful’ because it allows implicit arguments. Implicit arguments are useful in Haskell so that you don’t have to pass all variables to auxiliary functions; but I think that’s a fringe case.

Identification - a summary

Type Checking

Type checking checks rules about types against expressions. At their simplest types are sets of values. The main purpose of having a type checking is to prevent errors at run time by noticing programming errors at compile time. You have strong and weakly typed languages. Strongly typed languages have certain ‘guarantees’ that a specified set of errors cannot occur.

Static vs. Dynamic type systems

A static type system:

A dynamic type system:

Static is better because..

No doubt there is also ‘Dynamic is better because..’ somewhere…

Polymorphism

A language is polymorpgic if it allows language constructs to have more than one type; overloading or subtyping. If you did FUN then you know a lot about polymorphism and why it is handy. Allows for generic data structures and functions.

Basic type checking

A declaration

A statement

An expression

New types

New types are usually either distinct or synonymous. Most languages use a mixture.

Recursive Types

Obviously you can have recursive types. Bear in mind in C it only is permitted if you use pointers. Other languages do this too, apparently it’s t stop infinite comparison (e.g. if you went a == b it would loop).

Type conversions and subtyping

Some types may be able to convert into other types based on a set of rules. For example adding an int and a float together. Usually the type checker inserts the transformation at compile time. You can also do explicit conversion e.g. float(3).

Overloading

Already discussed this briefly, pretty obvious what overloading is, the slides are a bit confusing looking.

Type checking - a summary

Comments

blog comments powered by Disqus