Lightweight Higher-Kinded Polymorphism

  • Jeremy Yallop
  • Leo White
Part of the Lecture Notes in Computer Science book series (LNCS, volume 8475)

Abstract

Higher-kinded polymorphism —i.e. abstraction over type constructors— is an essential component of many functional programming techniques such as monads, folds, and embedded DSLs. ML-family languages typically support a form of abstraction over type constructors using functors, but the separation between the core language and the module language leads to awkwardness as functors proliferate.

We show how to express higher-kinded polymorphism in OCaml without functors, using an abstract type app to represent type application, and opaque brands to denote abstractable type constructors. We demonstrate the flexibility of our approach by using it to translate a variety of standard higher-kinded programs into functor-free OCaml code.

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. [Baars and Swierstra(2002)]
    Baars, A.I., Swierstra, S.D.: Typing dynamic typing. In: ICFP 2002, pp. 157–166. ACM, New York (2002), ISBN 1-58113-487-8Google Scholar
  2. [Chambart and Henry(2012)]
    Chambart, P., Henry, G.: Experiments in generic programming: runtime type representation and implicit values. In: OCaml Users and Developers Workshop (2012)Google Scholar
  3. [Hinze(2000)]
    Hinze, R.: Efficient generalized folds. In: Jeuring, J. (ed.) Proceedings of the 2nd Workshop on Generic Programming, Ponte de Lima, Portugal, pp. 1–16 (July 2000)Google Scholar
  4. [Hudak et al.(2007)Hudak, Hughes, Peyton Jones, and Wadler]
    Hudak, P., Hughes, J., Peyton Jones, S., Wadler, P.: A history of Haskell: Being lazy with class. In: Proceedings of the Third ACM SIGPLAN Conference on History of Programming Languages, HOPL III, pp. 12–1–12–55. ACM, New York (2007) ISBN 978-1-59593-766-7Google Scholar
  5. [Hughes(2000)]
    Hughes, J.: Generalising monads to arrows. Science of Computer Programming 37(13), 67–111 (2000) ISSN 0167-6423Google Scholar
  6. [Jeltsch(2010)]
    Jeltsch, W.: Generic record combinators with static type checking. In: Proceedings of the 12th International ACM SIGPLAN Symposium on Principles and Practice of Declarative Programming, pp. 143–154. ACM (2010)Google Scholar
  7. [Jones(1995)]
    Jones, M.P.: A system of constructor classes: overloading and implicit higher-order polymorphism. Journal of Functional Programming 5, 1–35 (1995) ISSN 1469-7653Google Scholar
  8. [Kiselyov and Shan(2007)]
    Kiselyov, O., Shan, C.-C.: Lightweight static capabilities. Electron. Notes Theor. Comput. Sci. 174(7), 79–104 (2007) ISSN 1571-0661Google Scholar
  9. [Kiselyov et al.(2004)Kiselyov, Lämmel, and Schupke]
    Kiselyov, O., Lämmel, R., Schupke, K.: Strongly typed heterogeneous collections. In: Proceedings of the 2004 ACM SIGPLAN Workshop on Haskell, pp. 96–107. ACM (2004)Google Scholar
  10. [Leroy(1995)]
    Leroy, X.: Applicative functors and fully transparent higher-order modules. In: Proceedings of the 22Nd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 1995, pp. 142–153. ACM, New York (1995) ISBN 0-89791-692-1, http://doi.acm.org/10.1145/199448.199476, doi:10.1145/199448.199476
  11. [Löh and Hinze(2006)]
    Löh, A., Hinze, R.: Open data types and open functions. In: Proceedings of the 8th ACM SIGPLAN International Conference on Principles and Practice of Declarative Programming, PPDP 2006, pp. 133–144. ACM, New York (2006) ISBN 1-59593-388-3Google Scholar
  12. [McBride and Paterson(2008)]
    McBride, C., Paterson, R.: Applicative programming with effects. J. Funct. Program. 18(1), 1–13 (2008) ISSN 0956-7968Google Scholar
  13. [Pottier and Gauthier(2004)]
    Pottier, F., Gauthier, N.: Polymorphic typed defunctionalization. In: Proceedings of the 31st ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2004, pp. 89–98. ACM, New York (2004) ISBN 1-58113-729-XGoogle Scholar
  14. [Reynolds(1972)]
    Reynolds, J.C.: Definitional interpreters for higher-order programming languages. In: Proceedings of the ACM Annual Conference, ACM 1972, vol. 2, pp. 717–740. ACM, New York (1972)Google Scholar
  15. [Schrijvers et al.(2008)Schrijvers, Peyton Jones, Chakravarty, and Sulzmann]
    Schrijvers, T., Peyton Jones, S., Chakravarty, M., Sulzmann, M.: Type checking with open type functions. In: Proceedings of the 13th ACM SIGPLAN International Conference on Functional Programming, ICFP 2008, pp. 51–62. ACM, New York (2008) ISBN 978-1-59593-919-7Google Scholar
  16. [Swamy et al.(2011)Swamy, Guts, Leijen, and Hicks]
    Swamy, N., Guts, N., Leijen, D., Hicks, M.: Lightweight monadic programming in ML. In: Proceedings of the 16th ACM SIGPLAN International Conference on Functional Programming, ICFP 2011, pp. 15–27. ACM, New York (2011) ISBN 978-1-4503-0865-6Google Scholar
  17. [Voigtländer(2008)]
    Voigtländer, J.: Asymptotic improvement of computations over free monads. In: Audebaud, P., Paulin-Mohring, C. (eds.) MPC 2008. LNCS, vol. 5133, pp. 388–403. Springer, Heidelberg (2008)CrossRefGoogle Scholar
  18. [Wadler and Blott(1989)]
    Wadler, P., Blott, S.: How to make ad-hoc polymorphism less ad hoc. In: Proceedings of the 16th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 1989, pp. 60–76. ACM, New York (1989) ISBN 0-89791-294-2Google Scholar
  19. [Yallop and Kiselyov(2010)]
    Yallop, J., Kiselyov, O.: First-class modules: hidden power and tantalizing promises. In: ACM SIGPLAN Workshop on ML, Baltimore, Maryland, United States (September 2010)Google Scholar
  20. [Yorgey et al.(2012)Yorgey, Weirich, Cretin, Peyton Jones, Vytiniotis, and Magalhães]
    Yorgey, B.A., Weirich, S., Cretin, J., Peyton Jones, S., Vytiniotis, D., Magalhães, J.P.: Giving Haskell a promotion. In: Proceedings of the 8th ACM SIGPLAN Workshop on Types in Language Design and Implementation, TLDI 2012, pp. 53–66. ACM, New York (2012) ISBN 978-1-4503-1120-5Google Scholar

Copyright information

© Springer International Publishing Switzerland 2014

Authors and Affiliations

  • Jeremy Yallop
    • 1
  • Leo White
    • 1
  1. 1.University of CambridgeUK

Personalised recommendations