## Practical type inference for

### BibTeX

@MISC{Peyton_practicaltype,

author = {Simon Peyton and Jones Dimitrios Vytiniotis and Stephanie C. Weirich and Mark Shields and Simon Peyton Jones and Stephanie Weirich and Mark Shields},

title = {Practical type inference for},

year = {}

}

### OpenURL

### Abstract

arbitrary-rank types

### Citations

938 | A theory of type polymorphism in programming
- Milner
- 1978
(Show Context)
Citation Context ...ons in this figure have already been shown. In particular the relation between the syntax-directed and the non syntax-directed Damas-Milner type system is captured by the theorem below. Theorem 4.4 ((=-=Milner, 1978-=-; Damas & Milner, 1982)) Suppose that t contains no type annotations and the context Γ contains only Damas-Milner types. 1. If Γ ⊢ DM poly sd t : σ then Γ ⊢ DM t : σ. 2. If Γ ⊢ DM t : σ then there is ... |

706 |
Types and Programming Languages
- Pierce
- 2002
(Show Context)
Citation Context ...ranslates to the System-F term e. Furthermore the term e will have type ρ in System F’s type system; we write Γ ⊢ F e : ρ. (We do not give the type system for System F here because it is so standard (=-=Pierce, 2002-=-). The interested reader can find it in the Technical Appendix (Vytiniotis et al., 2005).) The translated, System F terms have explicit type annotations on binders. For example, rule abs1 from Figure ... |

359 |
Principal type-schemes for functional programs
- Damas, Milner
- 1982
(Show Context)
Citation Context ...erature, the term “type” is often used to mean monotype, but we prefer to be more explicit here. 3.2 Exploiting type annotations Haskell and ML are both based on the classic Damas-Milner type system (=-=Damas & Milner, 1982-=-), which we review in Section 4.2. This type system has the remarkable property that a compiler can infer the principal type for a polymorphic function, without any help from the programmer. Furthermo... |

226 | TIL: A type-directed optimizing compiler for ML
- TARDITI, MORRISETT, et al.
- 1996
(Show Context)
Citation Context ...king the System F program at a later stage (which is very easy to do) gives a very strong consistency check that the intermediate stages have not performed an invalid transformation (Morrisett, 1995; =-=Tarditi et al., 1996-=-; Shao, 1997; Peyton Jones & Santos, 1998). In the rest of this section we show how to specify the translation into System F. 4.8.1 Translating terms The term “type-directed” translation comes from th... |

195 | A short cut to deforestation
- Gill, Launchbury, et al.
- 1993
(Show Context)
Citation Context ...nd of the definition. 2 In Haskell, back-quotes turn a function such as bnd into an infix operator.Practical type inference for arbitrary-rank types 5 Data structure fusion. Short-cut deforestation (=-=Gill et al., 1993-=-) makes use of build with type build :: forall a. (forall b. (a -> b -> b) -> b -> b) -> [a] Encapsulation. The encapsulated state monad ST (Launchbury & Peyton Jones, 1995) requires a function runST ... |

164 | Local type inference
- Pierce, Turner
- 1998
(Show Context)
Citation Context ...niversal quantification “∀”.) Our work draws together and applies Odersky & Läufer’s type system for arbitrary-rank types (Odersky & Läufer, 1996), and Pierce & Turner’s idea of local type inference (=-=Pierce & Turner, 1998-=-). The resulting type system, which we describe in Section 4, has the following properties: • It is a conservative extension of Damas-Milner: any program typeable with Damas-Milner remains typeable. •... |

123 | Unification under a mixed prefix
- Miller
- 1992
(Show Context)
Citation Context ...ncounters a ∀ quantifier in one type, it insistsPractical type inference for arbitrary-rank types 55 on a ∀ in the other. This is called “unification under a mixed prefix” and has been well studied (=-=Miller, 1992-=-). The typing rule is now the same for both inference and checking, so we can use use a direction-polymorphic rule: Γ ⊢⇓ e1 : Bool Γ ⊢δ e2 : ρ Γ ⊢δ e3 : ρ if Γ ⊢δ if e1 then e2 else e3 : ρ We prefer c... |

102 |
Polymorphic type inference and containment
- Mitchell
- 1988
(Show Context)
Citation Context ...misation subsumption It turns out that our deep skolemisation relation corresponds to the predicative restriction of a subsumption relation (denoted with ⊢ η σ1 � σ2) originally proposed by Mitchell (=-=Mitchell, 1988-=-). Theorem 9.1 ⊢ dsk σ1 � σ2 if and only if ⊢ η σ1 � σ2. Mitchell’s original relation, also referred to as Mitchell’s containment relation, is used in type inference for the System F language, closed ... |

102 | Compiling With Types
- Morrisett
- 1995
(Show Context)
Citation Context ...ermore, type-checking the System F program at a later stage (which is very easy to do) gives a very strong consistency check that the intermediate stages have not performed an invalid transformation (=-=Morrisett, 1995-=-; Tarditi et al., 1996; Shao, 1997; Peyton Jones & Santos, 1998). In the rest of this section we show how to specify the translation into System F. 4.8.1 Translating terms The term “type-directed” tra... |

99 | Tackling the awkward squad: monadic input/output, concurrency, exceptions, and foreign-language calls in haskell - Jones - 2002 |

95 | A new approach to generic functional programming
- Hinze
- 1999
(Show Context)
Citation Context ...mel & Peyton Jones, 2003) has functions such as: gmapT :: forall a. Data a => (forall b. Data b => b -> b) -> a -> a Hinze’s work on generic programming also makes extensive use of higher-rank types (=-=Hinze, 2000-=-). Invariants. Several authors have explored the idea of using the type system to encode data type invariants, via so-called nested data types (Bird & Paterson, 1999; Okasaki, 1999; Hinze, 2001). For ... |

95 | Putting type annotations to work
- Odersky, Laufer
- 1996
(Show Context)
Citation Context ...c type of f’s argument. (The explicit “forall” is GHC’s concrete syntax for universal quantification “∀”.) Our work draws together and applies Odersky & Läufer’s type system for arbitrary-rank types (=-=Odersky & Läufer, 1996-=-), and Pierce & Turner’s idea of local type inference (Pierce & Turner, 1998). The resulting type system, which we describe in Section 4, has the following properties: • It is a conservative extension... |

90 | Practical type inference for arbitrary-rank types
- Jones, Vytiniotis, et al.
- 2007
(Show Context)
Citation Context ... System F’s type system; we write Γ ⊢ F e : ρ. (We do not give the type system for System F here because it is so standard (Pierce, 2002). The interested reader can find it in the Technical Appendix (=-=Vytiniotis et al., 2005-=-).) The translated, System F terms have explicit type annotations on binders. For example, rule abs1 from Figure 8 becomes Γ, (x : τ) ⊢⇑ t : ρ ↦→ e abs1 Γ ⊢⇑ (\x.t) :(τ → ρ) ↦→ (λ(x : τ).e) The source... |

89 | An overview of the FLINT/ML compiler
- Shao
- 1997
(Show Context)
Citation Context ...ram at a later stage (which is very easy to do) gives a very strong consistency check that the intermediate stages have not performed an invalid transformation (Morrisett, 1995; Tarditi et al., 1996; =-=Shao, 1997-=-; Peyton Jones & Santos, 1998). In the rest of this section we show how to specify the translation into System F. 4.8.1 Translating terms The term “type-directed” translation comes from the fact that ... |

82 | A transformation-based optimiser for Haskell - Jones, Santos - 1998 |

78 | A direct algorithm for type inference in the rank-2 fragment of the second-order λ-calculus
- Kfoury, Wells
- 1994
(Show Context)
Citation Context ... rank-K subset of System F consists of all expressions that can be typed using types of rank � K . Kfoury and Wells show that typeability is decidable for rank � 2, and undecidable for all ranks � 3 (=-=Kfoury & Wells, 1994-=-). For the rank-2 fragment, the same paper gives a type inference algorithm. This inference algorithm is somewhat subtle, does not interact well with user-supplied type annotations, and has not, to ou... |

77 | Basic polymorphic typechecking
- Cardelli
- 1987
(Show Context)
Citation Context ...ng how many papers there are on type systems, there is surprising little literature on type inference that is aimed unambiguously at implementors. Cardelli’s paper was the first widely-read tutorial (=-=Cardelli, 1987-=-), with Hancock’s tutorial shortly afterwards (Hancock, 1987). More recently Mark Jones’s paper “Typing Haskell in Haskell” gave an executable implementation of Haskell’s type system (Jones, 1999). Ap... |

68 | R.: De Bruijn notation as a nested datatype
- Bird, Paterson
- 1999
(Show Context)
Citation Context ...so makes extensive use of higher-rank types (Hinze, 2000). Invariants. Several authors have explored the idea of using the type system to encode data type invariants, via so-called nested data types (=-=Bird & Paterson, 1999-=-; Okasaki, 1999; Hinze, 2001). For example, Paterson and Bird use the following data type to encode lambda terms, in which the nesting depth is reflected in the type: data Term v = Var v | App (Term v... |

57 | Typing dynamic typing
- Baars, Swierstra
- 2002
(Show Context)
Citation Context ... to give a pure result of type a. Dynamic types. Baars and Swierstra describe the following data type data Equal a b = Equal (forall f . f a -> f b) as a key part of their approach to dynamic typing (=-=Baars & Swierstra, 2002-=-). Generic programming. Various approaches to generic, or polytypic, programming make essential use of higher-rank types. For example, the “scrap your boilerplate” approach to generic programming (Läm... |

56 | Colored local type inference
- Odersky, Zenger, et al.
- 2001
(Show Context)
Citation Context ...cted. Odersky, Zenger and Zenger developed a more sophisticated scheme, called coloured local type inference, that is capable of propagating partial, as well as total, type information down the tree (=-=Odersky et al., 2001-=-). In effect, local type inference uses ⇑ and ⇓ in judgements, whereas coloured local type inference goes further and pushes ⇑ and ⇓ into types as well. The system is, however, rather complex. Coloure... |

53 | Scrap your boilerplate: a practical approach to generic programming - Lämmel, Jones - 2003 |

51 | Proofs about a folklore let-polymorphic type inference algorithm
- Lee, Yi
- 1998
(Show Context)
Citation Context ...ameter in Pascal, or a result-pointer argument in C: it serves as a location in which checkRho can return its result. This inward-propagation technique is well known to implementors as “Algorithm M” (=-=Lee & Yi, 1998-=-). We review it here because exactly the same technology will prove useful in Section 6, to implement the bidirectional type rules of Section 4.7. Here, for example is the Lit case for checkRho, which... |

30 | Scripting the type inference process
- Heeren, Hage, et al.
- 2003
(Show Context)
Citation Context ...lities – for example, subtype constraints, or Haskell’s class constraints. See Pottier and Rémy (2004) for a rather detailed treatment of this idea, which is also the basis for Helium’s type checker (=-=Heeren et al., 2003-=-).Practical type inference for arbitrary-rank types 67 Incidentally, it should be fairly easy to adapt the type inference engine in this paper to use the constraint-gathering approach. The Tc monad c... |

29 |
From fast exponentiation to square matrices: an adventure in types
- Okasaki
- 1999
(Show Context)
Citation Context ...of higher-rank types (Hinze, 2000). Invariants. Several authors have explored the idea of using the type system to encode data type invariants, via so-called nested data types (Bird & Paterson, 1999; =-=Okasaki, 1999-=-; Hinze, 2001). For example, Paterson and Bird use the following data type to encode lambda terms, in which the nesting depth is reflected in the type: data Term v = Var v | App (Term v) (Term v) | La... |

24 | Manufacturing datatypes
- Hinze
- 2001
(Show Context)
Citation Context ...types (Hinze, 2000). Invariants. Several authors have explored the idea of using the type system to encode data type invariants, via so-called nested data types (Bird & Paterson, 1999; Okasaki, 1999; =-=Hinze, 2001-=-). For example, Paterson and Bird use the following data type to encode lambda terms, in which the nesting depth is reflected in the type: data Term v = Var v | App (Term v) (Term v) | Lam (Term (Incr... |

23 | Qualified types for MLF - Leijen, Lh - 2005 |

20 | Semi-explicit first-class polymorphism for ML
- Garrigue, Rémy
- 1999
(Show Context)
Citation Context ...want to support separate compilation with stable interfaces. Recently, Le Botlan and Rémy – building on previous work by Garrigue and Rémy on extending ML with semi-explicit first-class polymorphism (=-=Garrigue & Remy, 1999-=-) – have described a new and ingenious type system, ML F , which supports the impredicative polymorphism of System F while retaining principal types (Le Botlan & Rmy, 2003). They achieve this remarkab... |

19 |
Type reconstruction in finite rank fragments of secondorder lambda calculus
- Kfoury, Tiuryn
- 1992
(Show Context)
Citation Context ...ch we allude to only in passing, leaving a more thorough treatment for Section 9. 3.1 Higher-ranked types The rank of a type describes the depth at which universal quantifiers appear contravariantly (=-=Kfoury & Tiuryn, 1992-=-): Here are some examples: Monotypes τ, σ 0 ::= a | τ1 → τ2 Polytypes σ n+1 ::= σ n | σ n → σ n+1 | ∀a.σ n+1 Int → Int Rank 0 ∀a.a → a Rank 1 Int → (∀a.a → a) Rank 1 (∀a.a → a) → Int Rank 2 Throughout... |

18 | Advanced Topics in Types and Programming Languages - Pierce - 2004 |

10 | A simple applicative language - Clement, Despeyroux, et al. - 1986 |

10 | Lexically scoped type variables. Microsoft Research. Available at http://research.microsoft. com/Users/simonpj/papers/scoped-tyvars - Shields, Jones - 2002 |

10 |
A sequent calculus for subtyping polymorphic types
- Tiuryn
- 2001
(Show Context)
Citation Context ...lation was shown to be undecidable (Tiuryn & Urzyczyn, 1996). Mitchell’s containment was originally presented in a declarative style; syntax-directed presentations of containment are also well known (=-=Tiuryn, 2001-=-; Longo et al., 1995). In particular, Longo et al. (1995) employ an idea similar to our deep skolemisation. To the best of our knowledge, no one had previously considered whether the predicative varia... |

5 | Simple, partial type inference for System F, based on type containment - Rémy - 2005 |

5 |
The subtyping problem for second order types is undecidable. Pages 74–85 of:Proc ieee symposium on logic in computer science (lics’96
- Tiuryn, Urzyczyn
- 1996
(Show Context)
Citation Context ... referred to as Mitchell’s containment relation, is used in type inference for the System F language, closed under η-expansion. The impredicative version of this relation was shown to be undecidable (=-=Tiuryn & Urzyczyn, 1996-=-). Mitchell’s containment was originally presented in a declarative style; syntax-directed presentations of containment are also well known (Tiuryn, 2001; Longo et al., 1995). In particular, Longo et ... |

3 |
A type checker. Pages 163–182 of: Peyton Jones, SL (ed), The implementation of functional programming languages
- Hancock
- 1987
(Show Context)
Citation Context ...sing little literature on type inference that is aimed unambiguously at implementors. Cardelli’s paper was the first widely-read tutorial (Cardelli, 1987), with Hancock’s tutorial shortly afterwards (=-=Hancock, 1987-=-). More recently Mark Jones’s paper “Typing Haskell in Haskell” gave an executable implementation of Haskell’s type system (Jones, 1999). Apart from the higher-rank aspect, the distinguishing feature ... |

3 |
Higher order unification 30 years later. 15th international workshop on higher order logic theorem proving and its applications (IWHOLTP’02). LNCS
- Huet
- 2002
(Show Context)
Citation Context ...tlan & Rmy, 2003). They achieve this remarkable rapprochement using a form of constrained polymorphism, with a constraint domain very reminiscent of Huet’s classic higher-order unification algorithm (=-=Huet, 2002-=-). Hence their system is actually more expressive than System F. Like us, they do not attempt to infer higher-ranked polymorphism, and instead accept that the programmer will have to guide the type sy... |

3 |
Typing Haskell in Haskell. Meijer, Erik (ed
- Jones
- 1999
(Show Context)
Citation Context ... (Cardelli, 1987), with Hancock’s tutorial shortly afterwards (Hancock, 1987). More recently Mark Jones’s paper “Typing Haskell in Haskell” gave an executable implementation of Haskell’s type system (=-=Jones, 1999-=-). Apart from the higher-rank aspect, the distinguishing feature of our presentation is the pervasive use of a monad to structure the type inference engine, and the use of the Expected Rho argument to... |

3 |
A logic of subtyping (extended abstract). Pages 292–299 of: |lics95
- Longo, Milsted, et al.
- 1995
(Show Context)
Citation Context ...wn to be undecidable (Tiuryn & Urzyczyn, 1996). Mitchell’s containment was originally presented in a declarative style; syntax-directed presentations of containment are also well known (Tiuryn, 2001; =-=Longo et al., 1995-=-). In particular, Longo et al. (1995) employ an idea similar to our deep skolemisation. To the best of our knowledge, no one had previously considered whether the predicative variant of the containmen... |

2 | ISBN 0-89791-595-X. type inference for arbitrary-rank types 81 - Press - 1990 |

2 | MLF: raising ML to the power - LeBotlan, &Rémy - 2003 |