Solutions of implication constraints yield type inference for more general algebraic data types (original) (raw)

Type inference with constrained types

Theory and Practice of Object Systems, 1999

In this paper we present a general framework HM(X) for Hindley/Milner style type systems with constraints. HM(X) stays in the tradition of the Hindley/Milner type system. Type systems in HM(X) are sound under a standard untyped compositional semantics that guarantees the slogan`well{typed programs can not go wrong'. Furthermore, we can give a generic type inference algorithm for HM(X). Under su cient conditions on X, type inference will always compute the principal type of a term. An instance of our framework which deals with polymorphic records is discussed. Also, we give a subtyping extension SHM(X) of our HM(X) system. In particular, the type inference algorithm for subtypes computes principal types. Simpli cation of the constraints inferred by the type inference algorithm is discussed for HM(X) and SHM(X).

Type Inference via Constraint Abduction for EADTs

Type inference for Hindley/Milner and variants is well understood as a constraint solving problem. Recent extensions to Hindley/Milner with user-definable primitive constraints, type annotations and an extended form of algebraic data types (loosely referred to as EADTs) force us to go beyond this approach to inference. Examples include generalized algebraic data types (GADTs) and multi-parameter type classes (MPTCs).

A Framework for Extended Algebraic Data Types

Lecture Notes in Computer Science, 2006

Extended forms of algebraic data types allow for sophisticated type extensions. A number of proposals exists and its often hard to understand what has been achieved. Here, we present a unifying framework which subsumes previous systems such as guarded recursive data types, the combination of type classes and existential types etc. We give an in depth discussion of the type inference problem and identify sufficient conditions under which we obtain completeness. Our results show that our system is practical and greatly extends the expressive power of languages such as Haskell and ML.

Type Checking and Inference Are Equivalent in Lambda Calculi with Existential Types

Functional and Constraint Logic Programming, 2010

This paper shows that type-checking and type-inference problems are equivalent in domain-free lambda calculi with existential types, that is, type-checking problem is Turing reducible to typeinference problem and vice versa. In this paper, the equivalence is proved for two variants of domain-free lambda calculi with existential types: one is an implication and existence fragment, and the other is a negation, conjunction and existence fragment. This result gives another proof of undecidability of type inference in the domain-free calculi with existence.

Existentially quantified type classes

2004

We present a formal framework for existential types and type classes. In contrast to Läufer's original proposal our system includes multi-parameter type classes and functional dependencies etc. Our system is powerful enough to express guarded recursive data types, a recent extension of algebraic data types. Type inference in our extension becomes a hard problem. For this purpose, we introduce a novel constraint solver. In general, we lose the principal types property. However, we consider several classes for which we infer a principal type if one exists. Our extension has been implemented as part of the Chameleon system.

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.

Simple unification-based type inference for GADTs

ACM SIGPLAN Notices, 2006

Generalized algebraic data types (GADTs), sometimes known as "guarded recursive data types" or "first-class phantom types", are a simple but powerful generalization of the data types of Haskell and ML. Recent works have given compelling examples of the utility of GADTs, although type inference is known to be difficult. Our contribution is to show how to exploit programmer-supplied type annotations to make the type inference task almost embarrassingly easy. Our main technical innovation is wobbly types, which express in a declarative way the uncertainty caused by the incremental nature of typical type-inference algorithms.

Sound and Decidable Type Inference for Functional Dependencies

Lecture Notes in Computer Science, 2004

Functional dependencies are a popular and useful extension to Haskell style type classes. In this paper, we give a reformulation of functional dependencies in terms of Constraint Handling Rules (CHRs). In previous work, CHRs have been employed for describing user-programmable type extensions in the context of Haskell style type classes. Here, we make use of CHRs to provide for the first time a concise result that under some sufficient conditions, functional dependencies allow for sound and decidable type inference. The sufficient conditions imposed on functional dependencies can be very limiting. We show how to safely relax these conditions.

Concoqtion: Mixing Indexed Types and Hindley-Milner Type Inference

2006

This paper addresses the question of how to extend OCaml's Hindley-Milner type system with types indexed by logical propositions and proofs of the Coq theorem prover, thereby providing an expressive and extensible mechanism for ensuring fine-grained program invariants. We propose adopting the approached used by Shao et al. for certified binaries. This approach maintains a phase distinction between the computational and logical languages, thereby limiting effects and non-termination to the computational language, and maintaining the decidability of the type system. The extension subsumes language features such as impredicative first-class (higher-rank) polymorphism and type operators, that are notoriously difficult to integrate with the Hindley-Milner style of type inference that is used in OCaml. We make the observation that these features can be more easily integrated with type inference if the inference algorithm is free to adapt the order in which it solves typing constraints to each program. To this end we define a novel "order-free" type inference algorithm. The key enabling technology is a graph representation of constraints and a constraint solver that performs Hindley-Milner inference with just three graph rewrite rules.

Types Inference for Generic Haskell

The more expressive a type system, the more type infor- mation has to be provided in a program. Having to provide a type is sometimes a pain, but lacking expressivity is often even worse. There is a continuous struggle between expressivity and (type-)verbosity. How- ever, even very expressive type systems allow type inference for parts of a program. Generic Haskell is an extension of Haskell that supports defin- ing generic functions. Generic Haskell assumes that the type of a generic function is explicitly specified. This is often no problem, but sometimes it is rather painful to have to specify a type - in particular for generic functions with many dependencies - and sometimes the specified type can be generalized. In this paper, we identify three type inference prob- lems specific to generic functions, and present (partial) solutions to each of them.