skip to main content
research-article
Open Access
Artifacts Available
Artifacts Evaluated & Functional

Simplicitly: foundations and applications of implicit function types

Published:27 December 2017Publication History
Skip Abstract Section

Abstract

Understanding a program entails understanding its context; dependencies, configurations and even implementations are all forms of contexts. Modern programming languages and theorem provers offer an array of constructs to define contexts, implicitly. Scala offers implicit parameters which are used pervasively, but which cannot be abstracted over.

This paper describes a generalization of implicit parameters to implicit function types, a powerful way to abstract over the context in which some piece of code is run. We provide a formalization based on bidirectional type-checking that closely follows the semantics implemented by the Scala compiler.

To demonstrate their range of abstraction capabilities, we present several applications that make use of implicit function types. We show how to encode the builder pattern, tagless interpreters, reader and free monads and we assess the performance of the monadic structures presented.

Skip Supplemental Material Section

Supplemental Material

implicitfunctiontypes.webm

References

  1. Runar Bjarnason. 2012. Stackless Scala With Free Monads. https://web.archive.org/web/20170107134129/http://blog. higher- order.com/assets/trampolines.pdf . (April 2012).Google ScholarGoogle Scholar
  2. Jacques Carette, Oleg Kiselyov, and Chung-chieh Shan. 2009. Finally Tagless, Partially Evaluated: Tagless Staged Interpreters for Simpler Typed Languages. J. Funct. Program. 19, 5 (Sept. 2009), 509–543. DOI: Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Cats. 2017. Cats: Lightweight, modular, and extensible library for functional programming. https://web.archive.org/web/ 20160219022626/https://github.com/typelevel/cats . (2017).Google ScholarGoogle Scholar
  4. Coq Team. 2017. The Coq Proof Assistant Reference Manual, Version 8.7.0. (2017).Google ScholarGoogle Scholar
  5. Thierry Coquand. 1996. An algorithm for type-checking dependent types. Science of Computer Programming 26, 1 (1996), 167 – 177. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Luis Damas and Robin Milner. 1982. Principal Type-schemes for Functional Programs. In Proceedings of the 9th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’82). ACM, New York, NY, USA, 207–212. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Dominique Devriese and Frank Piessens. 2011. On the Bright Side of Type Classes: Instance Arguments in Agda. In Proceedings of the 16th ACM SIGPLAN International Conference on Functional Programming (ICFP ’11). ACM, New York, NY, USA, 143–155. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Burak Emir, Andrew Kennedy, Claudio Russo, and Dachuan Yu. 2006. Variance and Generalized Constraints for C# Generics. In Proceedings of the 20th European Conference on Object-Oriented Programming (ECOOP’06). Springer-Verlag, Berlin, Heidelberg, 279–303. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. GHC. 2015. Glasgow Haskell Compiler Users Guide. https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/ glasgow_exts.html . (2015).Google ScholarGoogle Scholar
  10. Jean-Yves Girard. 1972. Interprétation fonctionelle et élimination des coupures de l’arithmétique d’ordre supérieur. Ph.D. Dissertation. PhD thesis, Université Paris VII.Google ScholarGoogle Scholar
  11. Georges Gonthier, Beta Ziliani, Aleksandar Nanevski, and Derek Dreyer. 2011. How to Make Ad Hoc Proof Automation Less Ad Hoc. In Proceedings of the 16th ACM SIGPLAN International Conference on Functional Programming (ICFP ’11). ACM, New York, NY, USA, 163–175. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Rod Johnson. 2002. Expert One-on-One J2EE Design and Development. Wrox Press Ltd., Birmingham, UK, UK.Google ScholarGoogle Scholar
  13. Mark P. Jones. 1995. Functional Programming with Overloading and Higher-Order Polymorphism. In Advanced Functional Programming, First International Spring School on Advanced Functional Programming Techniques-Tutorial Text. SpringerVerlag, London, UK, UK, 97–136. Google ScholarGoogle ScholarCross RefCross Ref
  14. Oleg Kiselyov and Chung-chieh Shan. 2004. Functional Pearl: Implicit Configurations–or, Type Classes Reflect the Values of Types. In Proceedings of the 2004 ACM SIGPLAN Workshop on Haskell (Haskell ’04). ACM, New York, NY, USA, 33–44. DOI: Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Kotlin. 2014. Type-Safe Groovy Style Builders in Kotlin. https://web.archive.org/web/20170607150651/https://kotlinlang. org/docs/reference/type- safe- builders.html . (2014).Google ScholarGoogle Scholar
  16. Jeffrey R. Lewis, John Launchbury, Erik Meijer, and Mark B. Shields. 2000. Implicit Parameters: Dynamic Scoping with Static Types. In Proceedings of the 27th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’00). ACM, New York, NY, USA, 108–118. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. Ulf Norell and others. 2017. Agda Documentation. https://web.archive.org/web/20170618112351/https://media.readthedocs. org/pdf/agda/v2.5.2/agda.pdf . (March 2017).Google ScholarGoogle Scholar
  18. Martin Odersky. 2017. Dotty Compiler: A Next Generation Compiler for Scala. https://web.archive.org/web/20170325001401/ http://dotty.epfl.ch/ . (2017).Google ScholarGoogle Scholar
  19. Martin Odersky and Matthias Zenger. 2005. Scalable Component Abstractions. In Proceedings of the 20th Annual ACM SIGPLAN Conference on Object-oriented Programming, Systems, Languages, and Applications (OOPSLA ’05). ACM, New York, NY, USA, 41–57. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. Martin Odersky, Matthias Zenger, and Christoph Zenger. 2001. Colored Local Type Inference. In Proc. ACM Symposium on Principles of Programming Languages. 41–53. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. Bruno C. d. S. Oliveira and William R. Cook. 2012. Extensibility for the Masses: Practical Extensibility with Object Algebras. In Proc. of the 26th European Conference on Object-Oriented Programming. ECOOP ’12, Vol. 7313. Springer Berlin Heidelberg, 2–27. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. Bruno C. d. S. Oliveira, Adriaan Moors, and Martin Odersky. 2010. Type Classes As Objects and Implicits. In Proceedings of the ACM International Conference on Object Oriented Programming Systems Languages and Applications (OOPSLA ’10). ACM, New York, NY, USA, 341–360. DOI: Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. Bruno C. d. S. Oliveira, Tom Schrijvers, Wontae Choi, Wonchan Lee, and Kwangkeun Yi. 2012. The Implicit Calculus: A New Foundation for Generic Programming. In Proceedings of the 33rd ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI ’12). ACM, New York, NY, USA, 35–44. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. Simon Peyton Jones, Dimitrios Vytiniotis, Stephanie Weirich, and Mark Shields. 2007. Practical Type Inference for Arbitraryrank Types. J. Funct. Program. 17, 1 (Jan. 2007), 1–82. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. Benjamin C. Pierce and David N. Turner. 2000. Local Type Inference. ACM Trans. Program. Lang. Syst. 22, 1 (Jan. 2000), 1–44. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. John Reynolds. 1974. Towards a theory of type structure. In Programming Symposium. Springer, 408–425. Google ScholarGoogle ScholarCross RefCross Ref
  27. Arjen Rouvoet. 2016. Programs for Free: Towards the Formalization of Implicit Resolution in Scala. Master’s thesis. TU Delft.Google ScholarGoogle Scholar
  28. Scalaz. 2017. Scalaz: An extension to the core Scala library for functional programming. https://web.archive.org/web/ 20170305041357/https://github.com/scalaz/scalaz/ . (2017).Google ScholarGoogle Scholar
  29. Tom Schrijvers, Bruno C d S Oliveira, and Philip Wadler. 2017. Cochis: Deterministic and Coherent Implicits. Technical Report CW705. KU Leuven.Google ScholarGoogle Scholar
  30. Matthieu Sozeau and Nicolas Oury. 2008. First-Class Type Classes. In Proceedings of the 21st International Conference on Theorem Proving in Higher Order Logics (TPHOLs ’08). Springer-Verlag, Berlin, Heidelberg, 278–293. Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. Wouter Swierstra. 2008. Data Types à La Carte. J. Funct. Program. 18, 4 (July 2008), 423–436. Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. Robbie Vanbrabant. 2008. Google Guice: Agile Lightweight Dependency Injection Framework (Firstpress). APress.Google ScholarGoogle ScholarDigital LibraryDigital Library
  33. Philip Wadler. 1998. The Expression Problem. https://web.archive.org/web/20170322142231/http://homepages.inf.ed.ac.uk/ wadler/papers/expression/expression.txt . (Dec. 1998).Google ScholarGoogle Scholar
  34. P. Wadler and S. Blott. 1989. How to Make Ad-hoc Polymorphism Less Ad Hoc. In Proceedings of the 16th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’89). ACM, New York, NY, USA, 60–76. Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. Adam Warski. 2013. MacWire: Lightweight and Nonintrusive Scala Dependency Injection Library. https://web.archive.org/ web/20170222065306/https://github.com/adamw/macwire . (2013).Google ScholarGoogle Scholar
  36. L. White, F. Bour, and J. Yallop. 2015. Modular implicits. ArXiv e-prints (Dec. 2015). arXiv: cs.PL/1512.01895Google ScholarGoogle Scholar
  37. Hongwei Xi and Frank Pfenning. 1999. Dependent Types in Practical Programming. In Proceedings of the 26th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’99). ACM, New York, NY, USA, 214–227. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Simplicitly: foundations and applications of implicit function types

        Recommendations

        Comments

        Login options

        Check if you have access through your login credentials or your institution to get full access on this article.

        Sign in

        Full Access

        PDF Format

        View or Download as a PDF file.

        PDF

        eReader

        View online with eReader.

        eReader
        About Cookies On This Site

        We use cookies to ensure that we give you the best experience on our website.

        Learn more

        Got it!