Using Constraint Handling Rules to Provide Static Type Analysis for the Q Functional Language (original) (raw)

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].

Type Processing by Constraint Reasoning

Lecture Notes in Computer Science, 2006

Herbrand constraint solving or unification has long been understood as an efficient mechanism for type checking and inference for programs using Hindley/Milner types. If we step back from the particular solving mechanisms used for Hindley/Milner types, and understand type operations in terms of constraints we not only give a basis for handling Hindley/Milner extensions, but also gain insight into type reasoning even on pure Hindley/Milner types, particularly for type errors. In this paper we consider typing problems as constraint problems and show which constraint algorithms are required to support various typing questions. We use a light weight constraint reasoning formalism, Constraint Handling Rules, to generate suitable algorithms for many popular extensions to Hindley/Milner types. The algorithms we discuss are all implemented as part of the freely available Chameleon system.

A polymorphic type system for prolog

Artificial Intelligence, 1984

We describe a polymorphic type scheme for Prolog which makes static type checking possible. Polymorphism gives a good degree of flexibility to the type system, and makes it intrude very little on a user's programming style. The only additions to the language are type declarations, which an interpreter can ignore if it so desires, with the guarantee that a well-typed program will behave identically with or without type checking. Our implementation is discussed and we observe that the type resolution problem for a Prolog program is another Prolog (meta)program.

A synthesis of type-checking and parsing

Computer Languages, 1993

Al~traet--The context-free grammars and parsers conventionally used to define and interpret concrete syntax lead to constrained expression notations. This paper gives algorithms which support less constrained, more intuitive notations. These algorithms can be viewed as context-sensitive parsers, where the context that is taken into account is the type structure of the expression. Or they can be viewed as type checkers that determine the form of the abstract syntax. The approach taken seamlessly integrates parsing and type-checking in the formalism of Markov algorithms. The interpretation of concrete syntax by these algorithms is unambiguous. At least one algorithm, DMA-T, is practical; its worst case time is O(tn 2) where n is the length of the expression and t is the maximum length of any type expression.

Non-standard type inference for functional programs

1998

While visiting the Computer Science Department of the University of Torino in November/December 1997. vi The evaluation rules for PCF are a subset of the ones for PCFP (in Figure 2.2), since the rules APP 2 and PROJ i (i ∈ {1, 2}) are not needed. All the results in the previous sections apply to PCF as well. 2.6 PCFP with primitive recursion In this section we introduce an extension of PCFP, called PCFP T , which is more suitable for expressing programs extracted from formal proofs. The language PCFP T is obtained from PCFP by adding a program constructor for primitive recursion over natural numbers (rec). There are also two constructors for specifying simplified uses of primitive recursion: the constructor it (for iteration) and the constructor case. PCFP T , which is a variant of Gödel's system T , is the language considered in Part III of this thesis. The term formation rules for the new constructors are in Fig. 2.4, and the evaluation rules are in Fig. 2.5. Since for every PCFP T term there is an equivalent (w.r.t. the interpretation in all the closed term model described in Section 2.4) PCFP term (see Fact 2.10 below), we have that all the results for PCFP presented in the previous sections apply to PCFP T as well.

Typing constraint logic programs

Theory and Practice of Logic Programming, 2001

We present a prescriptive type system with parametric polymorphism and subtyping for constraint logic programs. The aim of this type system is to detect programming errors statically. It introduces a type discipline for constraint logic programs and modules, while maintaining the capabilities of performing the usual coercions between constraint domains, and of typing meta-programming predicates, thanks to the exibility of subtyping. The property of subject reduction expresses the consistency of a prescriptive type system w.r.t. the execution model: if a program is ‘well-typed’, then all derivations starting from a ‘well-typed’ goal are again ‘well-typed’. That property is proved w.r.t. the abstract execution model of constraint programming which proceeds by accumulation of constraints only, and w.r.t. an enriched execution model with type constraints for substitutions. We describe our implementation of the system for type checking and type inference. We report our experimental resul...

Declaration-free type checking

Proceedings of the 12th ACM SIGACT-SIGPLAN symposium on Principles of programming languages - POPL '85, 1985

Conventional Milner-style polymorphic type checkers automatically infer types of functions and simple composite objects such as tuples. Types of recursive data structures (e.g. lists) have to be defined by the programmer through an abstract data type definition. In this paper, we show how abstract data types, involving type union and recursion, can be automatlcally inferred by a type checker. The language for describing such types is that of regular trees, a generalization of' regular expressions to denote sets of tree structured terms. Inference of these types is reducible to the problem of solving simultaneous inclusion inequations over regular trees. We present algorithms to solve such inequations. Using these techniques, programs without any type definitions and type annotations for functions can be type checked.