We study HMG(X), an extension of the constraint-based type system HM(X) with deep pattern matching, polymorphic recursion, and guarded algebraic data types. Guarded algebraic data types subsume the concepts known in the literature as indexed types, guarded recursive datatype constructors, (first-class) phantom types, and equality qualified types, and are closely related to inductive types. Their characteristic property is to allow every branch of a case construct to be typechecked under different assumptions about the type variables in scope. We prove that HMG(X) is sound and that, provided recursive definitions carry a type annotation, type inference can be reduced to constraint solving. Constraint solving is decidable, at least for some instances of X, but prohibitively expensive. Effective type inference for guarded algebraic data types is left as an issue for future research.
INTRODUCTIONMembers of the ML family of programming languages offer type inference in the style of Hindley [1969] andMilner [1978], making type annotations optional. Type inference can be decomposed into constraint generation and constraint solving phases, where constraints are, roughly speaking, systems of type equations. This remark has led to the definition of a family of constraint-based type systems, known as HM(X) [Odersky et al. 1999;Pottier and Rémy 2005], whose members exploit potentially more complex constraint languages, achieving greater expressiveness while still enjoying type inference in the style of Hindley and Milner.These programming languages also provide high-level facilities for defining and manipulating data structures, namely algebraic data types and pattern matching. In the setting of an explicitly typed calculus, Xi, Chen, and Chen [2003] have recently introduced guarded algebraic data types, an extension that offers significant new expressive power to programmers.The purpose of the present paper is to study how these two lines of research Permission to make digital/hard copy of all or part of this material without fee for personal or classroom use provided that the copies are not made or distributed for profit or commercial advantage, the ACM copyright/server notice, the title of the publication, and its date appear, and notice is given that copying is by permission of the ACM, Inc. To copy otherwise, to republish, to post on servers, or to redistribute to lists requires prior specific permission and/or a fee. . 2005], it is necessary to study their interaction with Hindley-Milner-style type inference. Furthermore, because type inference is best understood in a constraint-based setting, and because constraint-based type systems are more general than Hindley and Milner's original type system, we believe it is worth studying an extension of HM(X) with guarded algebraic data types.We proceed as follows. First, we present an untyped call-by-value λ-calculus featuring data constructors and pattern matching ( §2). (We believe that our results could be transferred to a call-by-name calculus without difficulty.) The...