| OCR Text |
Show second corresponds to the t literal and is Wanti = bool and Havei = ex.. Because there is no substitution that can make a equal to both int and bool, the type check fails. Contrast this with a successful case: pred r(int). pred p(int). ?- r(X), p(X). In this case, Want0 = int and Have0 = a for the r literal, and Wanti = int and Havei = a for the p literal. There exists a a = (a <- int), such that Wanto = a Have 0 and W anti = crHave lt Therefore the check succeeds. 2.3 Adding Inclusion To make this type system more interesting, we add a maximal type called any. We define any intuitively as follows: all ints are any s and all bools are any s. Our grammar is now: < Type> ::= int \ bool | any These types fall into a hierarchy most easily described by the diagram shown in Figure 2.1. More concisely, for every type T, T C any. Given this domain, it is now possible for data to have more than one type. In fact, we can think of any value's type as being a ordered set (using the ordering from Figure 2.1). For example, the type of the value 3 will be the ordered set {int, any}. It is notationally convenient to introduce a postfix operator f to indicate such sets. The operator will be used in the following way: <Type> f will indicate 10 int bool Figure 2.1. Simple type hierarchy |