Ulf's  >  PLD  >  Architecture  >  Type System >            related: 
                     
  Pro/Con    Type Annotations    ^...Type Systems    ^Flexibility      ^Principles      
     
   
typed prog.lang  TYPE SYSTEM   
 
 REQUIREMENTS 
   
    
  static
type
system
 
+
  dynamic
type
system
 
«Static type systems have had considerable success in popular programming languages. Consequently, the type checker helps enforce program invariants like "This variable is null or contains the address of a data record of type T". Experience has shown that the invariants imposed by a type system are easy to teach to programmers, helpful in finding common errors, and flexible enough for large classes of programs that programmers actually want to write. The flexibility comes in part from the fact that certain checks are not performed statically, but are instead enforced by simple dynamic checks.» [K Rustan M Leino: Extended Static Checking: A Ten-Year Perspective; 157-175 in: Informatics: 10 Years Back, 10 Years Ahead; LNCS 2000; 2001]
  error
discovery
 

  allow
wanted
programs
 

  learnability  

    
  static
type
system
 
In a statically typed language, the definition of the computational semantics needs to make sense only for legal programs, ie., the programs which passed the static type check Only program sources that comply with a type system should be considered real programs of a typed language; the other sources should be discarded before they are run» [TS])

«A major purpose of type systems is to avoid embarassing questions about representations [what is the effect of a conditional over a non-Boolean value, what is the set union of two functions, ...], and to forbid situations in which these questions might come up. In mathematics as in programming, types impose constraints that help to enforce correctness. Some untyped universes, like naive set theory, were found to be logically inconsistent, and typed versions were proposed to eliminate inconsistencies.» [TyOOL].

  cleaner
semantics
 
    
 
  static
type
system
 
«There are many advantages to having a statically type-checked language. These include providing earlier (and usually more accurate) information on programmer errors, providing documentation on the interface of components (e.g., procedures, functions, and packages or modules), eliminating the need for run-time checks, which can slow the program execution, and providing extra information that can be used in compiler optimization. One possible disadvantage of static typing is that because static type checkers are necessarily conservative, a static type checker for a programming language may disallow a program that would execute without error. Thus statically typed programming languages may be less expressive than dyncamically typed languages» [TyOOL].

«Type checking has proved to be very effective in catching a wide class of programming errors, from the trivial (misspelled identifiers) to the fairly deep (violations of data structure invariants). It makes program [sic!] considerably safer, ensuring integrity of data structures and type-correct interconnection of program components.

Safety is not the only motivation for equipping programming languages with type systems, however. Another motivation, which came first historically, is to facilitate the efficient compilation of programs. Static typing restricts the set of programs to be compiled ... Also, static typing guarantees certain properties and invariants on the data manipulated by the program; the compiler can take advantages of these semantic guarantees to generate better code. ... » [TiC].

  • Efficient compilation, eg., integer:floating-point arithmetics, working with data of different sizes
    «... The Fortran type system introduces a strict separation between integer numbers and floating-point numbers at compile-time. The main motivation for this separation, according to Fortran's designers, was to avoid the difficulties of handling mixed arithmetics at run-time. Thanks to the type system, the compiler "knows" when to generate integer arithmetic operations, float-point arithmetic operations, and conversions between integers and floats. Since then, this separation has permeated hardware design: most processor architectures provide separate register sets and arithmetic units for integers and for floats. In turn, this architectural bias makes it nearly impossible to generate efficient numerical code for a language whose type system does not statically distinguish floating-point numbers from integers.
    Another area where compilers rely heavily on static typing is the handling of variable-sized data. Different data types have different natural memory sizes: ... Precise knowledge of size information is necessary to generate corect code that allocates and operates over data structures. This knowledge is usually derived from the static typing information: the type of the data determines its memory size and layout
    » [TiC].
  •   error
    discovery
     

      documentation  

      efficient
    compilation
     

      disallow
    safe progs.
     

        
    Ulf Schünemann; ulf@cs.mun.ca; 031004