Advertisement

Principal Type Inference for GHC-Style Multi-parameter Type Classes

  • Martin Sulzmann
  • Tom Schrijvers
  • Peter J. Stuckey
Part of the Lecture Notes in Computer Science book series (LNCS, volume 4279)

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.

Keywords

Program Logic Type Class Type Inference Principal Type Type Annotation 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. 1.
    Damas, L., Milner, R.: Principal type-schemes for functional programs. In: Proc. of POPL 1982, pp. 207–212. ACM Press, New York (1982)Google Scholar
  2. 2.
    Demoen, B., la de Banda, M.G., Harvey, W., Marriott, K., Stuckey, P.J.: An overview of HAL. In: Jaffar, J. (ed.) CP 1999. LNCS, vol. 1713, pp. 174–189. Springer, Heidelberg (1999)Google Scholar
  3. 3.
    Faxén, K.F.: Haskell and principal types. In: Proc. of Haskell Workshop 2003, pp. 88–97. ACM Press, New York (2003)CrossRefGoogle Scholar
  4. 4.
    Frühwirth, T.: Constraint Handling Rules. In: Podelski, A. (ed.) Constraint Programming: Basics and Trends. LNCS, vol. 910. Springer, Heidelberg (1995)Google Scholar
  5. 5.
    Glasgow haskell compiler home page, http://www.haskell.org/ghc/
  6. 6.
    Hall, C.V., Hammond, K., Peyton Jones, S.L., Wadler, P.L.: Type classes in Haskell. ACM Transactions on Programming Languages and Systems 18(2), 109–138 (1996)CrossRefGoogle Scholar
  7. 7.
    Henderson, F., et al.: The Mercury language reference manual (2001), http://www.cs.mu.oz.au/research/mercury/
  8. 8.
    Henglein, F.: Type inference with polymorphic recursion. Transactions on Programming Languages and Systems 15(1), 253–289 (1993)CrossRefGoogle Scholar
  9. 9.
    Hugs home page, haskell.cs.yale.edu/hugs/
  10. 10.
    Jeffery, D., Henderson, F., Somogyi, Z.: Type classes in Mercury. In: Edwards, J. (ed.) Proc. Twenty-Third Australasian Computer Science Conf. Australian Computer Science Communications, vol. 22, pp. 128–135. IEEE Computer Society Press, Los Alamitos (2000)Google Scholar
  11. 11.
    Jones, M.P.: Coherence for qualified types. Research Report YALEU/DCS/RR-989, Yale University, Department of Computer Science (September 1993)Google Scholar
  12. 12.
    Jones, M.P.: Type classes with functional dependencies. In: Smolka, G. (ed.) ESOP 2000. LNCS, vol. 1782, p. 230. Springer, Heidelberg (2000)CrossRefGoogle Scholar
  13. 13.
    Peyton Jones, S., Jones, M.P., Meijer, E.: Type classes: an exploration of the design space. In: Haskell Workshop (June 1997)Google Scholar
  14. 14.
    Kuncak, V., Rinard, M.: Structural subtyping of non-recursive types is decidable. In: Proc. of LICS 2003, pp. 96–107. IEEE Computer Society Press, Los Alamitos (2003)Google Scholar
  15. 15.
    Lassez, J., Maher, M., Marriott, K.: Unification revisited. In: Foundations of Deductive Databases and Logic Programming. Morgan Kaufmann, San Francisco (1987)Google Scholar
  16. 16.
    Läufer, K.: Type classes with existential types. Journal of Functional Programming 6(3), 485–517 (1996)MATHCrossRefMathSciNetGoogle Scholar
  17. 17.
    Läufer, K., Odersky, M.: Polymorphic type inference and abstract data types. ACM Trans. Program. Lang. Syst. 16(5), 1411–1430 (1994)CrossRefGoogle Scholar
  18. 18.
    Miller, D.: Unification under a mixed prefix. J. Symb. Comput. 14(4), 321–358 (1992)MATHCrossRefGoogle Scholar
  19. 19.
    Milner, R.: A theory of type polymorphism in programming. Journal of Computer and System Sciences 17, 348–375 (1978)MATHCrossRefMathSciNetGoogle Scholar
  20. 20.
    Odersky, M., Läufer, K.: Putting type annotations to work. In: Proc. of POPL 1996, pp. 54–67. ACM Press, New York (1996)CrossRefGoogle Scholar
  21. 21.
    Peyton Jones, S. (ed.): Haskell 1998 Language and Libraries: The Revised Report. Cambridge University Press, Cambridge (2003)Google Scholar
  22. 22.
    Plasmeijer, M.J., van Eekelen, M.C.J.D.: Language report Concurrent Clean. Technical Report CSI-R9816, Computing Science Institute. University of Nijmegen, Nijmegen, The Netherlands (June 1998), ftp://ftp.cs.kun.nl/pub/Clean/Clean13/doc/refman13.ps.gz
  23. 23.
    Shoenfield, J.R.: Mathematical Logic. Addison-Wesley, Reading (1967)MATHGoogle Scholar
  24. 24.
    Stuckey, P.J., Sulzmann, M.: A theory of overloading. ACM Transactions on Programming Languages and Systems (TOPLAS) 27(6), 1–54 (2005)CrossRefGoogle Scholar
  25. 25.
    Sulzmann, M., Duck, G.J., Peyton Jones, S., Stuckey, P.J.: Understanding functional dependencies via Constraint Handling Rules. Journal of Functional Programming (to appear, 2006)Google Scholar
  26. 26.
    Sulzmann, M., Schrijvers, T., Stuckey, P.J.: Principal type inference for GHC-style multi-parameter type classes. Technical report, The National University of Singapore (2006)Google Scholar
  27. 27.
    Sulzmann, M., Wazny, J., Stuckey, P.J.: A framework for extended algebraic data types. In: Hagiya, M., Wadler, P. (eds.) FLOPS 2006. LNCS, vol. 3945, pp. 47–64. Springer, Heidelberg (2006)CrossRefGoogle Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2006

Authors and Affiliations

  • Martin Sulzmann
    • 1
  • Tom Schrijvers
    • 2
  • Peter J. Stuckey
    • 3
  1. 1.School of ComputingNational University of SingaporeSingapore
  2. 2.Department of Computer ScienceKatholieke Universiteit LeuvenHeverleeBelgium
  3. 3.NICTA Victoria Laboratory, Department of Computer Science and Software EngineeringThe University of MelbourneAustralia

Personalised recommendations