## Principal type inference for GHCstyle multi-parameter type classes (2006)

Venue: | In Proc. of APLAS’06 |

Citations: | 5 - 5 self |

### BibTeX

@TECHREPORT{Sulzmann06principaltype,

author = {Martin Sulzmann and Tom Schrijvers and Peter J. Stuckey},

title = {Principal type inference for GHCstyle multi-parameter type classes},

institution = {In Proc. of APLAS’06},

year = {2006}

}

### OpenURL

### Abstract

Abstract. We observe that the combination of multi-parameter type classes with existential types and type annotations leads to a loss of principal types and undecidability of type inference. This may be a surprising fact for users of these popular features. We conduct a concise investigation of the problem and are able to give a type inference procedure which, if successful, computes principal types under the conditions imposed by the Glasgow Haskell Compiler (GHC). Our results provide new insights on how to perform type inference for advanced type extensions. 1 Introduction Type systems are important building tools in the design of programming lan-guages. They are typically specified in terms of a set of typing rules which are formulated in natural deduction style. The standard approach towards estab-lishing type soundness is to show that any well-typed program cannot go wrong at run-time. Hence, one of the first tasks of a compiler is to verify whether aprogram is well-typed or not.

### Citations

952 | A theory of type polymorphism in programming
- Milner
- 1978
(Show Context)
Citation Context ... a type inference algorithm which automatically checks whether a program is well-typed and as a side-effect assigns types to program text. For programming languages based on the Hindley/Milner system =-=[19]-=- we can typically verify that type inference is complete and the inferred type is principal [1]. Completeness guarantees that if the program is well-typed type inference ⋆ Research Assistant of the fu... |

372 |
Principle type-schemes for functional programs
- Damas, Milner
- 1982
(Show Context)
Citation Context ...side-effect assigns types to program text. For programming languages based on the Hindley/Milner system [19] we can typically verify that type inference is complete and the inferred type is principal =-=[1]-=-. Completeness guarantees that if the program is well-typed type inference ⋆ Research Assistant of the fund for Scientific Research - Flanders (Belgium)(F.W.O. - Vlaanderen)swill infer a type for the ... |

220 |
Uni revisited
- Lassez, Maher, et al.
- 1988
(Show Context)
Citation Context ... the form t1 = t2 (type equations) and TC ¯t (type class constraints). We generally assume that the reader is familiar with the concepts of substitutions, unifiers, most general unifiers (m.g.u.) etc =-=[15]-=- and first-order logic [23]. We write [t/a] to denote the simultaneous substitution of variables ai by types ti for i = 1, .., n. We use common notation for Boolean conjunction (∧), implication (⊃) an... |

194 | Constraint Handling Rules
- Fruhwirth
- 2009
(Show Context)
Citation Context ... class constraint solver is parameterized in terms of these rewrite relations. Following our earlier work [24], we formally define these rewrite relations in terms of Constraint Handling Rules (CHRs) =-=[4]-=-. For each declaration instance D ⇒ TC ¯t we introduce the single-headed CHR rule TC ¯t ⇐⇒ D. In case, the context D is empty, we generate rule TC ¯t ⇐⇒ True. The set of all such generated constraint ... |

160 | Type classes with functional dependencies
- Jones
- 2000
(Show Context)
Citation Context ...tion, we convince the type inferencer that a=b. Then, the program is accepted. 2 The informed reader will notice that instead of lexically scoped type annotations we could use functional dependencies =-=[12]-=- to enforce that a=b. In our opinion, for many practical examples the reverse argument applies as well. Furthermore, lexically scoped type annotations are a more light-weight extension than functional... |

138 | Type inference with polymorphic recursion
- Henglein
- 1993
(Show Context)
Citation Context ...y/Milner type system, we sacrifice completeness for the sake of decidability. For example, some well-typed programs with polymorphic recursion are rejected because it makes type inference undecidable =-=[8]-=-. Instead, we demand that if type inference succeeds, the inferred type must be principal. An incomplete type inference has already been implemented in GHC; for example it does not produce a type for ... |

126 | Type classes in Haskell
- Hall, Hammond, et al.
- 1996
(Show Context)
Citation Context ...ed by straightforward application of the CHR Soundness Lemma. The reason for defining solutions operationally rather than logically is due to the type-preserving dictionary-passing translation scheme =-=[6]-=- employed in GHC. Briefly, assumption constraints D are taken literally and turned into dictionaries. Rewriting them would break separate compilation. Hence, in our definition of solutions we guarante... |

124 | Unification under a mixed prefix
- Miller
- 1992
(Show Context)
Citation Context ...Int is not a valid solution of ∀b.True ⊃ (B a b ∧ tr = Int) because the variable b escapes. We will check for escaping of universal variables by applying a well-known technique known as Skolemization =-=[18]-=-. Skolemization of ∀b.True ⊃ (B a b ∧ tr = Int) yields True ⊃ (B a Sk ∧ tr = Int). The constraint B a Sk ∧ tr = Int is clearly not a valid solution because of the Skolem constructor Sk. We explore sol... |

97 | Putting type annotations to work
- Odersky, Läufer
- 1996
(Show Context)
Citation Context ...xtension of the Hindley/Milner system and available as part of Haskell [21] implementations such as GHC [5] and HUGS [9]. GHC and HUGS also support (boxed) existential types [17] and type annotations =-=[20]-=-. 1 It is the combination of all these features that make MPTCs so popular among programmers. In this paper, we make the following contributions: – We answer the above question negatively. We show tha... |

95 | Type classes: An exploration of the design space
- Jones, Jones, et al.
- 1997
(Show Context)
Citation Context ...that any type possibly given to the program can be derived from the inferred type. Here, we ask the question whether this happy situation continues in the case of multi-parameter type classes (MPTCs) =-=[13]-=-, a popular extension of the Hindley/Milner system and available as part of Haskell [21] implementations such as GHC [5] and HUGS [9]. GHC and HUGS also support (boxed) existential types [17] and type... |

93 | A Theory of Qualified Types
- Jones
- 1992
(Show Context)
Citation Context ...es such as instance StackImpl s Int and thus we find besides tx = a a second solution tx = Int. The danger then is that the meaning of programs may become ambiguous. This is a well-recognized problem =-=[11, 24]-=-. For this reason, Haskell demands that programs must be unambiguous. We therefore follow Haskell and rule out ambiguous programs. In terms of implication constraints, the unambiguity condition says t... |

62 | Polymorphic type inference and abstract data types
- Laufer, Odersky
- 1994
(Show Context)
Citation Context ... (MPTCs) [13], a popular extension of the Hindley/Milner system and available as part of Haskell [21] implementations such as GHC [5] and HUGS [9]. GHC and HUGS also support (boxed) existential types =-=[17]-=- and type annotations [20]. 1 It is the combination of all these features that make MPTCs so popular among programmers. In this paper, we make the following contributions: – We answer the above questi... |

53 | A Theory of Overloading
- Stuckey, Sulzmann
(Show Context)
Citation Context ...es such as instance StackImpl s Int and thus we find besides tx = a a second solution tx = Int. The danger then is that the meaning of programs may become ambiguous. This is a well-recognized problem =-=[11, 24]-=-. For this reason, Haskell demands that programs must be unambiguous. We therefore follow Haskell and rule out ambiguous programs. In terms of implication constraints, the unambiguity condition says t... |

44 | An overview of HAL
- Demoen, Banda, et al.
- 1999
(Show Context)
Citation Context ... written this introduction as if Haskell (GHC and HUGS) is the only language (systems) that supports MPTCs. Type classes are also supported in a number of other languages such as Mercury [7, 10], HAL =-=[2]-=- and Clean [22]. However, as far as we know there is no formal description of multi-parameter type classes and the combination with existential types and type annotations. From now on, we will use MPT... |

29 | Type classes with existential types
- Läufer
- 2005
(Show Context)
Citation Context ...lti-parameter type classes and the combination with existential types and type annotations. From now on, we will use MPTCs to refer to the system that combines all these features. For example, Läufer =-=[16]-=- only considered the combination of singleparameter type classes and existential types. The only formal description available is our own previous work [27] where we introduce the more general system o... |

25 | M.: Structural subtyping of non-recursive types is decidable
- Kuncak, Rinard
- 2003
(Show Context)
Citation Context ...program text may now have implication constraints on the left-hand side of ⊃. But then solving these “extended” implication constraints is very close to solving of first-order formulae. Previous work =-=[14]-=- shows that solving of first-order formula with subtype constraints is decidable but has a non-elementary complexity. Note that via Haskell type classes we can encode complex relations such as subtypi... |

22 |
compiler home
- haskell
(Show Context)
Citation Context ... happy situation continues in the case of multi-parameter type classes (MPTCs) [13], a popular extension of the Hindley/Milner system and available as part of Haskell [21] implementations such as GHC =-=[5]-=- and HUGS [9]. GHC and HUGS also support (boxed) existential types [17] and type annotations [20]. 1 It is the combination of all these features that make MPTCs so popular among programmers. In this p... |

22 | A framework for extended algebraic data types
- Sulzmann, Wazny, et al.
- 2006
(Show Context)
Citation Context ...ines all these features. For example, Läufer [16] only considered the combination of singleparameter type classes and existential types. The only formal description available is our own previous work =-=[27]-=- where we introduce the more general system of extended algebraic data types (EADTs). Notice that in [27] we discuss type checking but not type inference. In the next section, we give a cursory introd... |

20 |
P.J.: Understanding functional dependencies via constraint handling rules
- Sulzmann, Duck, et al.
- 2007
(Show Context)
Citation Context ...e first two conditions define solutions in terms of the operational reading of instances as CHRs. They imply the logical statement P |= C ⊃ F . This 3 There are other more liberal instance conditions =-=[25]-=- which guarantee the same. 11scan be verified by straightforward application of the CHR Soundness Lemma. The reason for defining solutions operationally rather than logically is due to the type-preser... |

14 | Eekelen. Language report Concurrent Clean
- Plasmeijer, van
- 1998
(Show Context)
Citation Context ...introduction as if Haskell (GHC and HUGS) is the only language (systems) that supports MPTCs. Type classes are also supported in a number of other languages such as Mercury [7, 10], HAL [2] and Clean =-=[22]-=-. However, as far as we know there is no formal description of multi-parameter type classes and the combination with existential types and type annotations. From now on, we will use MPTCs to refer to ... |

11 |
Type classes in Mercury
- Jeery, Henderson, et al.
- 1998
(Show Context)
Citation Context ...blem. We have written this introduction as if Haskell (GHC and HUGS) is the only language (systems) that supports MPTCs. Type classes are also supported in a number of other languages such as Mercury =-=[7, 10]-=-, HAL [2] and Clean [22]. However, as far as we know there is no formal description of multi-parameter type classes and the combination with existential types and type annotations. From now on, we wil... |

8 |
and principal types
- Haskell
- 2003
(Show Context)
Citation Context ...Section 4). We omit proofs for brevity, sketches can be found in [26]. To the best of our knowledge, we are the first to point out precisely the problem behind type inference for MPTCs. Previous work =-=[3]-=- only reports the loss of principal types but does not provide many clues about how to tackle the inference problem. We have written this introduction as if Haskell (GHC and HUGS) is the only language... |

5 |
et al. The Mercury language reference manual
- Henderson
- 2001
(Show Context)
Citation Context ...blem. We have written this introduction as if Haskell (GHC and HUGS) is the only language (systems) that supports MPTCs. Type classes are also supported in a number of other languages such as Mercury =-=[7, 10]-=-, HAL [2] and Clean [22]. However, as far as we know there is no formal description of multi-parameter type classes and the combination with existential types and type annotations. From now on, we wil... |

1 | Type inference with polymorphic recursion - auresearchmercury - 1993 |

1 | 18. Dale Miller. Unification under a mixed prefix - Syst - 1994 |