Chapter 10

Treating and Type Testing

Talk about a treat

—Charles Collins:Any Old Iron (1911)

One, two, three, testing

—20th century catchphrase

The topics of this chapter—treating and type testing, and the associated operators TREAT and IS_T—have been touched on, and indeed illustrated, several times in earlier chapters. However, it’s time to get more specific. In fact, there’s quite a lot more to be said about these matters, as will quickly become clear.

Note: Once again the pertinent prescriptions—here, IM Prescriptions 14 and 15—are deliberately worded in such a way as to apply to multiple as well as single inheritance, and to tuple and relation types as well as scalar types. As usual, however, the present chapter discusses single inheritance and scalar types only; multiple inheritance is discussed in Part III of this book and tuple and relation types are discussed in Part IV.

IM PRESCRIPTION 14: TREAT

Let X be an expression, let T be a type, and let DT(X) and T overlap. Then an operator of the form

TREAT_AS_T ( X )

(or logical equivalent thereof) shall be supported, with semantics as follows: If v(X) is not of type T, then a type error shall occur; otherwise, the declared type of the invocation TREAT_AS_T(X) shall be T, and the result of that invocation, r say, shall be equal to v(X) (hence, MST(r) shall be equal to MST(X) also).

image

Compared to the Explorations version, IM Prescription ...

Get Type Inheritance and Relational Theory now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.