Extending Hindley-Milner Type Inference with Coercive Structural Subtyping

  • Dmitriy Traytel
  • Stefan Berghofer
  • Tobias Nipkow
Part of the Lecture Notes in Computer Science book series (LNCS, volume 7078)

Abstract

We investigate how to add coercive structural subtyping to a type system for simply-typed lambda calculus with Hindley-Milner polymorphism. Coercions allow to convert between different types, and their automatic insertion can greatly increase readability of terms. We present a type inference algorithm that, given a term without type information, computes a type assignment and determines at which positions in the term coercions have to be inserted to make it type-correct according to the standard Hindley-Milner system (without any subtypes). The algorithm is sound and, if the subtype relation on base types is a disjoint union of lattices, also complete. The algorithm has been implemented in the proof assistant Isabelle.

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. 1.
    Benke, M.: Complexity of type reconstruction in programming languages with subtyping. Ph.D. thesis, Warsaw University (1997)Google Scholar
  2. 2.
    Bourdoncle, F., Merz, S.: On the integration of functional programming, class-based object-oriented programming, and multi-methods. Research Report 26, Centre de Mathématiques Appliquées, Ecole des Mines de Paris (March 1996)Google Scholar
  3. 3.
    Coq development team: The Coq proof assistant reference manual. INRIA (2010), http://coq.inria.fr version 8.3
  4. 4.
    Frey, A.: Satisfying subtype inequalities in polynomial space. Theor. Comput. Sci. 277(1-2), 105–117 (2002)MathSciNetCrossRefMATHGoogle Scholar
  5. 5.
    Fuh, Y.C., Mishra, P.: Type inference with subtypes. In: Ganzinger, H. (ed.) ESOP 1988. LNCS, vol. 300, pp. 94–114. Springer, Heidelberg (1988)CrossRefGoogle Scholar
  6. 6.
    Luo, Z.: Coercions in a polymorphic type system. Mathematical Structures in Computer Science 18(4), 729–751 (2008)MathSciNetCrossRefMATHGoogle Scholar
  7. 7.
    Milner, R.: A theory of type polymorphism in programming. J. Comput. Syst. Sci. 17(3), 348–375 (1978)MathSciNetCrossRefMATHGoogle Scholar
  8. 8.
    Mitchell, J.C.: Coercion and type inference. In: POPL, pp. 175–185 (1984)Google Scholar
  9. 9.
    Mitchell, J.C.: Type inference with simple subtypes. J. Funct. Program. 1(3), 245–285 (1991)MathSciNetCrossRefMATHGoogle Scholar
  10. 10.
    Nipkow, T.: Order-sorted polymorphism in Isabelle. In: Huet, G., Plotkin, G. (eds.) Logical Environments, pp. 164–188. CUP (1993)Google Scholar
  11. 11.
    Nordlander, J.: Polymorphic subtyping in O’Haskell. Sci. Comput. Program. 43(2-3), 93–127 (2002)MathSciNetCrossRefMATHGoogle Scholar
  12. 12.
    Pierce, B.C.: Types and Programming Languages. MIT Press, Cambridge (2002)MATHGoogle Scholar
  13. 13.
    Pottier, F.: Simplifying subtyping constraints: a theory. Information & Computation 170(2), 153–183 (2001)MathSciNetCrossRefMATHGoogle Scholar
  14. 14.
    Pratt, V.R., Tiuryn, J.: Satisfiability of inequalities in a poset. Fundam. Inform. 28(1-2), 165–182 (1996)MathSciNetMATHGoogle Scholar
  15. 15.
    Saïbi, A.: Typing algorithm in type theory with inheritance. In: POPL, pp. 292–301 (1997)Google Scholar
  16. 16.
    Shields, M., Peyton Jones, S.: Object-oriented style overloading for Haskell. In: First Workshop on Multi-language Inferastructure and Interoperability (BABEL 2001), Firenze, Italy (September 2001)Google Scholar
  17. 17.
    Simonet, V.: Type Inference with Structural Subtyping: A Faithful Formalization of an Efficient Constraint Solver. In: Ohori, A. (ed.) APLAS 2003. LNCS, vol. 2895, pp. 283–302. Springer, Heidelberg (2003)CrossRefGoogle Scholar
  18. 18.
    Tiuryn, J.: Subtype inequalities. In: LICS, pp. 308–315 (1992)Google Scholar
  19. 19.
    Traytel, D., Berghofer, S., Nipkow, T.: Extending Hindley-Milner type inference with coercive subtyping (long version) (2011), www.in.tum.de/~nipkow/pubs/coercions.pdf
  20. 20.
    Wand, M., O’Keefe, P.: On the complexity of type inference with coercion. In: FPCA 1989: Functional Programming Languages and Computer Architecture, pp. 293–298. ACM, New York (1989)Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2011

Authors and Affiliations

  • Dmitriy Traytel
    • 1
  • Stefan Berghofer
    • 1
  • Tobias Nipkow
    • 1
  1. 1.Institut für InformatikTechnische Universität MünchenGarchingGermany

Personalised recommendations