Results

**1 - 1**of**1**### 15-819K: Logic Programming Lecture 10

, 2006

"... In this lecture we extend the system of simple types from the previous lecture to encompass polymorphism. There are some technical pitfalls, and some plausible systems do not satisfy type preservation. We discuss three ways to restore type preservation. 10.1 Heterogeneous and Homogeneous Lists Types ..."

Abstract
- Add to MetaCart

In this lecture we extend the system of simple types from the previous lecture to encompass polymorphism. There are some technical pitfalls, and some plausible systems do not satisfy type preservation. We discuss three ways to restore type preservation. 10.1 Heterogeneous and Homogeneous Lists Types such as natural numbers, be it in binary or in unary notation, are easy to specify and use in the system from the previous lecture. Generic data structures such as lists, on the other hand, present difficulties. Recall the type predicate for lists: list([]). list([X|Xs]):- list(Xs). The difficulty is that for lists in general there is no restriction on X: it can have arbitrary type. When we try to give the declarations list: type. [] : list. ’. ’ :?, list-> list. we realize that there is nothing sensible we can put as the type of the first argument of cons. 1 Two solutions suggest themselves. One is to introduce a universal type “any ” and ensure that t: any for all terms t. This destroys the property of 1 Recall that [X|Xs] is just alternate syntax for’.’(X, Xs)