Lecture 5 - Type Systems
Lecture 5 - Type Systems
• Type safety
Type Systems
• A type system is type safe (strongly typed) when no program can violate the
distinctions between types defined in the corresponding language.
Classification of types
function printArray(array) {
for (var i = 0; i < array.length; i++)
print(array[i]);
}
Or:
function forEach(array, action) {
for (var i = 0; i < array.length; i++)
action(array[i]);
}
• Booleans
• Characters
• Integers
• Reals
• Fixed point
• Complex
• Void
• Enumerations
• Intervals
Why is void a type?
• void f (...){...}
• This means an integer can be used in place of Dwarf and vice versa - so
this helps in documentation but does not support any stronger checking
Contrast with this in C++
• The primary composite types, among which are records, variant records and
unions, arrays and pointers in detail.
• The concept of type equivalence.
• The concept of compatibility and the related concepts of coercion and
conversion.
• The concept of overloading, when a single name denotes more than one object
and static disambiguation.
• The concept of universal polymorphism, when a single name denotes an object
that belongs to many different types.
• Type inference, that is mechanisms that allow the type of a complex expression
to be determined from the types of its elementary types.
• Techniques for runtime checking for dangling references.
• Techniques for garbage collection.