f Practice questions for quiz 6, CSCI 3675

Computer Science 3675
Section 001
Fall 2006
Practice questions for quiz 6

  1. True or false.

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

    2. Standard ML is a strongly statically typed language. Therefore, in Standard ML, it is not possible to get a type error at run time.

    3. Java is strongly statically typed.

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

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

  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. (Try an example. What kind of thing makes sense?)

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

  5. Polymorphism without type variables typically requires dynamic type checking. Give an example where a run-time (dynamic) type check is required when there are no type variables, but where type variables would allow the compiler to perform static type checking.

  6. Suppose that a tree type is defined in Cinnameg with two constructors, as follows.

        Species Tree =
            leaf String
          | node (Tree,Tree)
        %Species
    
    Using primitive recursion, write a definition of a function that takes a tree and returns the total number of nodes (leaves and internal nodes) in the tree.

  7. Using the same type as in the preceding exercise, again using primitive recursion, write a function that takes a tree and returns the concatenation of all of the strings in the leaves in the tree, from left to right.