Chapter 7 Type Systems

Type systems

Type systems

Type systems

Type systems

Type systems and subroutines

Type checking

Type checking

Type checking

Polymorphism

Polymorphism

The meaning of "type"

The meaning of "type"

The meaning of "type"

Three ways to think about types

Three ways to think about types

Three ways to think about types

Orthogonality

Orthogonality

Classification of types

Enumeration types

type weekday = (sun, mon, tue, wed, thue, fri, sat);
for today := mon to fri do begin ...
var daily_attendance : array [weekday] of integer;

Enumerations

enum weekday {sun, mon, tue, wed, thu, fri, sat};
int main()
{

  enum weekday day1 = sun;
  enum weekday day2 = mon;
  enum weekday day3;
  day3 = day1 + day2;
}

Subranges

Composite types

Composite types

Type equivalence

Type equivalence

Type conversions and casts

Type conversions and casts

Type compatibility

Containers and universal reference types

Type inference

type Atype = 0..20;
type Btype = 10..30;

var a: Atype;
var b: Btype;

Type inference

What about indexing?

TYPE CHECKING IN THE ML FAMILY

Type classes for overloaded functions in Haskell

Equality and assignment

Equality and assignment

Records/Structures and Variants/Unions

Records/Structures and Variants/Unions

Simplifying the syntax

with complex.complicated.deep.stuff do
begin

  fieldx := 'STUFF GOES HERE';
  fieldy := 'STUFF GOES THERE';
  fieldz := 'STUFF GOES EVERYWHERE'

end;

Arrays

Arrays

Array declarations

Slices

Conformant arrays

Dynamic arrays

Memory layout

Strings

Sets

Pointers and recursive types

Pointers and models

Pointers and value models

Note on page 353 relating to "stack smashing":

C allows conflation of pointer arithmetic with array access

Garbage collection

Garbage collection

Garbage collection

Garbage collection

Garbage collection

7.8 Lists

7.8 Lists

7.10 Equality and assignment

Equality and assignment

7.11 Wrapping up

7.11 Wrapping up

7.11 Wrapping up