Computer Science 3675
Fall 2002
Practice questions for quiz 3

  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. What is the value of Scheme expression (car (cdr (cons 'horse (cons 'zebra ()))))?

  3. Write a Scheme function called drop so that (drop n L) returns the result of removing the first n members from list L. If L has fewer than n members, then (drop n L) should return the empty list. For example, (drop 2 '(4 8 3 5 7)) = (3 5 7) and (drop 3 '(5 2)) = (). Be careful to use Scheme syntax correctly.

  4. Write the filter function in Scheme. That is, write a filter function so that (filter p L) returns a list of all members x of list L such that (p x) is true. Do not try to make it lazy.

  5. 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.

  6. 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].

  7. 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?

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

  9. 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?