Computer Science 3675
Fall 2001
Practice questions for quiz 5

  1. True/False

    1. Type checking was first introduced to programming languages so that compilers could detect type errors made by programmers.

    2. C++ uses name equivalence of types defined using typedef.

    3. In a typeless language, all type checking done at run time.

    4. In a strongly typed language, type errors can never occur at run time.

    5. Polymorphism is most useful in designing custom applications, and is rarely used in function libraries.

  2. Polymorphism without type variables typically requires that a programmer defeat the compile-time type system. Give an example where the type system would need to be defeated without type variables, but where type variables would allow the compiler to perform type checking.

  3. What is the most general polymorphic type of function f defined by f(x) = tail(right(x))? Use type variables. Function right takes the right-hand member of an ordered pair.

  4. What is the most general polymorphic type of the Astarte function filter? Filter is defined so that (filter f L) a list of all members x of list L such that f(x) is true. For example, if function positive returns true on a positive number and false on a nonpositive number, then (filter positive [9,-2,-3,6]) = [9,6].

  5. Types and functions can both be viewed as kinds of encapsulations. A function encapsulates an algorithm for solving a problem; it hides the details of the algorithm. What does a type encapsulate?

  6. Why do most modern languages employ name equivalence instead of structural equivalence for types?

  7. When a compiler performs type inference, what is it doing? What information does it use as its source of information, and what information does it infer?