Abstract
Haskell 2010 lacks flexibility in creating instances of type classes for type constructors with multiple type arguments. We would like to make the order of type arguments to a type constructor irrelevant to how type class instances can be specified. None of the currently available techniques in Haskell allows to do this in a satisfactory way.
To flexibly create type-class instances we have added the concept of type-level lambdas as anonymous type synonyms to Haskell. As higher-order unification of lambda terms in general is undecidable, we take a conservative approach to equality between type-level lambdas. We propose a number of small changes to the constraint solver that will allow type-level lambdas to be used in type class instances. We show that this satisfies our goal, while having only minor impact on existing Haskell code.
This is a preview of subscription content, log in via an institution.
Buying options
Tax calculation will be finalised at checkout
Purchases are for personal use only
Learn about institutional subscriptionsReferences
Alkemade, T.P.: UnitTyped (2012). https://hackage.haskell.org/package/unittyped. Accessed 9 Apr 2014
Chakravarty, M.M.T., Keller, G., Jones, S.P., Marlow, S.: Associated types with class. In: Proceedings of POPL 2005: The 32nd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pp. 1–13. ACM (2005)
Elliott, C.: TypeCompose (2007–2013). https://hackage.haskell.org/package/TypeCompose. Accessed 10 Dec 2013
Gill, A., Paterson, R.: Transformers (2009–2012). Accessed 10 Dec 2013
Hall, C., Hammond, K., Jones, S.P., Wadler, P.: Type classes in haskell. ACM Trans. Program. Lang. Syst. 18, 241–256 (1996)
Huet, G.P.: The undecidability of unification in third order logic. Inf. Control 22(3), 257–267 (1973)
Kmett, E.A.: Bifunctors (2011–2013). https://hackage.haskell.org/package/bifunctors. Accessed 10 Dec 2013
Marlow, S.: Haskell 2010 language report (2010). https://www.haskell.org/onlinereport/haskell2010/
Neubauer, M., Thiemann, P.: Type classes with more higher-order polymorphism. In: Proceedings of the Seventh ACM SIGPLAN International Conference on Functional Programming, ICFP 2002, pp. 179–190. ACM, New York (2002)
Peterson, J., Jones, M.: Implementing type classes. In: Proceedings of the ACM SIGPLAN 1993 Conference on Programming Language Design and Implementation, PLDI 1993, pp. 227–236. ACM, New York (1993)
The GHC Team: The Glorious Glasgow Haskell Compilation System User’s Guide. http://www.haskell.org/ghc/docs/7.6.3/html/users_guide/index.html
Vytiniotis, D., Jones, S.P., Schrijvers, T., Sulzmann, M.: OutsideIn(X) Modular type inference with local assumptions. J. Funct. Program. 21(4–5), 333–412 (2011)
Acknowledgments
We would like to thank the anonymous reviewers for their extensive comments.
Author information
Authors and Affiliations
Corresponding author
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2016 Springer International Publishing Switzerland
About this paper
Cite this paper
Alkemade, T., Jeuring, J. (2016). Type Class Instances for Type-Level Lambdas in Haskell. In: Serrano, M., Hage, J. (eds) Trends in Functional Programming. TFP 2015. Lecture Notes in Computer Science(), vol 9547. Springer, Cham. https://doi.org/10.1007/978-3-319-39110-6_4
Download citation
DOI: https://doi.org/10.1007/978-3-319-39110-6_4
Published:
Publisher Name: Springer, Cham
Print ISBN: 978-3-319-39109-0
Online ISBN: 978-3-319-39110-6
eBook Packages: Computer ScienceComputer Science (R0)