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.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Preview
Unable to display preview. Download preview PDF.
Similar content being viewed by others
References
Damas, L., Milner, R.: Principal type-schemes for functional programs. In: Proc. of POPL 1982, pp. 207–212. ACM Press, New York (1982)
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)
Faxén, K.F.: Haskell and principal types. In: Proc. of Haskell Workshop 2003, pp. 88–97. ACM Press, New York (2003)
Frühwirth, T.: Constraint Handling Rules. In: Podelski, A. (ed.) Constraint Programming: Basics and Trends. LNCS, vol. 910. Springer, Heidelberg (1995)
Glasgow haskell compiler home page, http://www.haskell.org/ghc/
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)
Henderson, F., et al.: The Mercury language reference manual (2001), http://www.cs.mu.oz.au/research/mercury/
Henglein, F.: Type inference with polymorphic recursion. Transactions on Programming Languages and Systems 15(1), 253–289 (1993)
Hugs home page, haskell.cs.yale.edu/hugs/
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)
Jones, M.P.: Coherence for qualified types. Research Report YALEU/DCS/RR-989, Yale University, Department of Computer Science (September 1993)
Jones, M.P.: Type classes with functional dependencies. In: Smolka, G. (ed.) ESOP 2000. LNCS, vol. 1782, p. 230. Springer, Heidelberg (2000)
Peyton Jones, S., Jones, M.P., Meijer, E.: Type classes: an exploration of the design space. In: Haskell Workshop (June 1997)
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)
Lassez, J., Maher, M., Marriott, K.: Unification revisited. In: Foundations of Deductive Databases and Logic Programming. Morgan Kaufmann, San Francisco (1987)
Läufer, K.: Type classes with existential types. Journal of Functional Programming 6(3), 485–517 (1996)
Läufer, K., Odersky, M.: Polymorphic type inference and abstract data types. ACM Trans. Program. Lang. Syst. 16(5), 1411–1430 (1994)
Miller, D.: Unification under a mixed prefix. J. Symb. Comput. 14(4), 321–358 (1992)
Milner, R.: A theory of type polymorphism in programming. Journal of Computer and System Sciences 17, 348–375 (1978)
Odersky, M., Läufer, K.: Putting type annotations to work. In: Proc. of POPL 1996, pp. 54–67. ACM Press, New York (1996)
Peyton Jones, S. (ed.): Haskell 1998 Language and Libraries: The Revised Report. Cambridge University Press, Cambridge (2003)
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
Shoenfield, J.R.: Mathematical Logic. Addison-Wesley, Reading (1967)
Stuckey, P.J., Sulzmann, M.: A theory of overloading. ACM Transactions on Programming Languages and Systems (TOPLAS) 27(6), 1–54 (2005)
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)
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)
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)
Author information
Authors and Affiliations
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2006 Springer-Verlag Berlin Heidelberg
About this paper
Cite this paper
Sulzmann, M., Schrijvers, T., Stuckey, P.J. (2006). Principal Type Inference for GHC-Style Multi-parameter Type Classes. In: Kobayashi, N. (eds) Programming Languages and Systems. APLAS 2006. Lecture Notes in Computer Science, vol 4279. Springer, Berlin, Heidelberg. https://doi.org/10.1007/11924661_2
Download citation
DOI: https://doi.org/10.1007/11924661_2
Publisher Name: Springer, Berlin, Heidelberg
Print ISBN: 978-3-540-48937-5
Online ISBN: 978-3-540-48938-2
eBook Packages: Computer ScienceComputer Science (R0)