A polymorphic type system for prolog (original) (raw)

A Gradual Polymorphic Type System with Subtyping for Prolog

Technical Communications of the 28th International Conference on Logic Programming (ICLP’12)

Although Prolog was designed and developed as an untyped language, there have been numerous attempts at proposing type systems suitable for it. The goal of research in this area has been to make Prolog programming easier and less error-prone not only for novice users, but for the experienced programmer as well. Despite the fact that many of the proposed systems have deep theoretical foundations that add types to Prolog, most Prolog vendors are still unwilling to include any of them in their compiler’s releases. Hence standard Prolog remains an untyped language. Our work can be understood as a step towards typed Prolog. We propose an extension to one of the most extensively studied type systems proposed for Prolog, the Mycroft-O’Keefe type system, and present an implementation in XSB-Prolog. The resulting type system can be characterized as a Gradual type system, where the user begins with a completely untyped version of his program, and incrementally obtains information about the possible types of the predicates he defines from the system itself, until type signatures are found for all the predicates in the source code.

Type analysis of prolog using type graphs

Journal of Logic Programming, 1995

Type analysis of Prolog is of .primary importance for high-performance compilers since type information may lead to better indexing and to sophisticated specializations of unification and built-in predicates, to name a few. However, these optimization often require a sophisticated type inference system capable of inferring disjunctive and recursive types, and hence expensive in computation time. The purpose of this paper is to describe a type analysis system for Prolog based on abstract interpretation and type graphs (i.e., disjunctive rational trees) with this functionality. The system (about 15,000 lines of C) consists of the combination of a generic fixpoint algorithm, a generic pattern domain, and a type graph domain. The main contribution of the paper is to show that this approach can be engineered to be practical for medium-sized programs without sacrificing accuracy. The main technical contribution to achieve this result is a novel widening operator for type graphs which appears to be accurate and effective in keeping the sizes of the graphs, and hence the computation time, reasonably small. <] 1. INTRODUCTION Although Prolog is an untyped language, type analysis of the language is important since it allows the improvement of indexing, to specialize unification, and to pro-*This paper is a revised and extended version of [27].

Typed Prolog: A Semantic Reconstruction of the Mycroft-O'Keefe Type System

1991

Keefe 25] presented a declaration-based type system for Prolog. However, they did not clarify the semantics of the type system, leading to several criticisms being voiced against it. We propose that the language accepted by this type system be viewed as a typed variant of Prolog, called Typed Prolog. We de ne the formal semantics of Typed Prolog along the lines of many-sorted logic and polymorphic lambda calculus. Typed Prolog also supports a form of type inference called type reconstruction which takes a Typed Prolog program with missing type declarations, and reconstructs the most general type declarations satisfying the language de nition. This approach contrasts with the inference based type systems which have been widely pursued heretofore.

Parametric Polymorphism for Typed Prolog and lambdaProlog

1997

Typed Prolog and Prolog are logic programming languages with a strict typing discipline which is based on simple types with variables. Experiments show that this discipline does not handle properly common logic programming practices used in Prolog. For instance, the usual transformation for computing the Clark completion of a Prolog program does not work well with some typed programs. We observe that the so-called head-condition is at the heart of these problems, and conclude that it should be enforced. We propose a second-order scheme which is compatible with usual practices. It allows quantifying types and terms, passing type and term parameters to goals and terms, and to express type guards for selecting goals. We give its syntax and deduction rules, and propose a solution to keep the concrete notation of programs close to the usual one.

Parametric polymorphism for typed Prolog and λProlog

Lecture Notes in Computer Science, 1996

Typed Prolog and Prolog are logic programming languages with a strict typing discipline which is based on simple types with variables. Experiments show that this discipline does not handle properly common logic programming practices used in Prolog. For instance, the usual transformation for computing the Clark completion of a Prolog program does not work well with some typed programs. We observe that the so-called head-condition is at the heart of these problems, and conclude that it should be enforced. We propose a second-order scheme which is compatible with usual practices. It allows quantifying types and terms, passing type and term parameters to goals and terms, and to express type guards for selecting goals. We give its syntax and deduction rules, and propose a solution to keep the concrete notation of programs close to the usual one.

Integrating Java and Prolog through generic methods and type inference

Proceedings of the ACM Symposium on Applied Computing, 2008

P@J is a framework, based on the tuProlog open-source engine, allowing Prolog code to be used as possible implementation of a Java method: Java annotations are used for specifying all the necessary information to fill the Java-Prolog gap. This framework is useful to inject a declarative, logicbased paradigm into mainstream object-oriented programming, so as to easily code functionalities related to automatic reasoning, adaptivity, and conciseness in expressing algorithms.

Type checking and type deduction techniques for polymorphic programming languages

2018

In this paper wc present some of the syntactic issues that arise in polymorphic programming languages. In particular we examine type checking and deduction in two different polymorphic type structures: the parametric lambda-calculus (with let construct) and the polymorphic or secondorder lambda-calculus'. In both approaches the behavior of types is formalized with type inference rules. Examples of programming languages following those approaches are presented and some of their specific problems studied.

A Type System for CHR

Lecture Notes in Computer Science, 2005

We propose a generic type system for the Constraint Handling Rules (CHR), a rewriting rule language for implementing constraint solvers. CHR being a high-level extension of a host language, such as Prolog or Java, this type system is parameterized by the type system of the host language. We show the consistency of the type system for CHR w.r.t. its operational semantics. We also study the case when the host language is a constraint logic programming language, typed with the prescriptive type system we developed in our previous work. In particular, we show the consistency of the resulting type system w.r.t. the extended execution model CLP+CHR. This system is implemented through an extension of our type checker TCLP for constraint logic languages. We report on experimental results about the type-checking of 12 CHR solvers and programs, including TCLP itself.

Type Inference for Mobile Ambients in Prolog

Electronic Notes in Theoretical Computer Science, 2004

The type system for the ambient calculus M 3 [8] is presented in a new form that derives the type of a term with the minimal set of mobility assumptions, and is therefore more amenable than the original form to a translation into a type inference algorithm. From the new formulation a Prolog program is derived, which implements a type inference algorithm for M 3 analogous to the one previously specified through formal rules. The implementation exploits in the standard way the peculiarities of the logic programming paradigm, and is therefore, in a sense, more abstract than the original algorithm's specification itself.