TC-4 FAQ

Stupid Types

One can legitimately wonder whether the following program is correct:

let type weirdo = array of weirdo
in
  print("I'm a creep.\n")
end

the answer is “yes”, as nothing prevents this in the Tiger specifications. This type is not usable though.

Is type::Field useful?
Using std::pair in type::Record is probably enough, and simpler.
Is nil compatible with objects?

For instance, is the following example valid?

var a : Object := nil

The answer is yes: nil is both compatible with records and objects.

Can one redefine the built-in class Object?

Yes, if the rules of the Tiger Compiler Reference Manual are honored, notably:

  • Every class has a super class, defaulting to the built-in class Object (syntactic sugar of class without an extends clause).
  • Recursive inheritance (within the same block of types) is forbidden.

For example,

let class Object {} in end

is invalid, since it is similar to

let class Object extends Object {} in end

and recursive inheritance is invalid.

One can try and introduce a Dummy type as a workaround

let
  class Dummy {}
  class Object extends Dummy {}
in
end

but this is just postponing the problem, since the code above is the same as the following:

let
  class Dummy  extends Object {}
  class Object extends Dummy  {}
in
end

where there is still a recursive inheritance.

The one solution is to define our Dummy type beforehand (i.e., in its own block of type declarations), then to redefine Object.

/* Valid.  */
let
  class Dummy {}
in
  let
    class Object extends Dummy {}
  in
  end
end

Take care: this new Object type is different from the built-in one. The code below gives an example of an invalid mix of these two types.

let
  class Dummy {}
  function get_builtin_object() : Object = new Object /* builtin */
in
  let
    class Object extends Dummy {} /* custom */

    /* Invalid assignment, since an instance of the builtin Object
       is *not* an instance of the custom Object.  */
    var o : Object /* custom */ := get_builtin_object() /* builtin */
  in
  end
end