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.
Supplemental Material
Available for Download
This artifact provides instructions to evaluate that the benchmarks presented in the paper are reproducible and the code snippets compile successfully.
- 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 Scholar
- 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 Scholar
Digital Library
- Cats. 2017. Cats: Lightweight, modular, and extensible library for functional programming. https://web.archive.org/web/ 20160219022626/https://github.com/typelevel/cats . (2017).Google Scholar
- Coq Team. 2017. The Coq Proof Assistant Reference Manual, Version 8.7.0. (2017).Google Scholar
- Thierry Coquand. 1996. An algorithm for type-checking dependent types. Science of Computer Programming 26, 1 (1996), 167 – 177. Google Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- GHC. 2015. Glasgow Haskell Compiler Users Guide. https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/ glasgow_exts.html . (2015).Google Scholar
- 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 Scholar
- 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 Scholar
Digital Library
- Rod Johnson. 2002. Expert One-on-One J2EE Design and Development. Wrox Press Ltd., Birmingham, UK, UK.Google Scholar
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
- 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 Scholar
Digital Library
- 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 Scholar
- Martin Odersky. 2017. Dotty Compiler: A Next Generation Compiler for Scala. https://web.archive.org/web/20170325001401/ http://dotty.epfl.ch/ . (2017).Google Scholar
- 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 Scholar
Digital Library
- Martin Odersky, Matthias Zenger, and Christoph Zenger. 2001. Colored Local Type Inference. In Proc. ACM Symposium on Principles of Programming Languages. 41–53. Google Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- Benjamin C. Pierce and David N. Turner. 2000. Local Type Inference. ACM Trans. Program. Lang. Syst. 22, 1 (Jan. 2000), 1–44. Google Scholar
Digital Library
- John Reynolds. 1974. Towards a theory of type structure. In Programming Symposium. Springer, 408–425. Google Scholar
Cross Ref
- Arjen Rouvoet. 2016. Programs for Free: Towards the Formalization of Implicit Resolution in Scala. Master’s thesis. TU Delft.Google Scholar
- 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 Scholar
- Tom Schrijvers, Bruno C d S Oliveira, and Philip Wadler. 2017. Cochis: Deterministic and Coherent Implicits. Technical Report CW705. KU Leuven.Google Scholar
- 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 Scholar
Digital Library
- Wouter Swierstra. 2008. Data Types à La Carte. J. Funct. Program. 18, 4 (July 2008), 423–436. Google Scholar
Digital Library
- Robbie Vanbrabant. 2008. Google Guice: Agile Lightweight Dependency Injection Framework (Firstpress). APress.Google Scholar
Digital Library
- 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 Scholar
- 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 Scholar
Digital Library
- Adam Warski. 2013. MacWire: Lightweight and Nonintrusive Scala Dependency Injection Library. https://web.archive.org/ web/20170222065306/https://github.com/adamw/macwire . (2013).Google Scholar
- L. White, F. Bour, and J. Yallop. 2015. Modular implicits. ArXiv e-prints (Dec. 2015). arXiv: cs.PL/1512.01895Google Scholar
- 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 Scholar
Digital Library
Index Terms
Simplicitly: foundations and applications of implicit function types
Recommendations
Dependent object types with implicit functions
Scala '19: Proceedings of the Tenth ACM SIGPLAN Symposium on ScalaDOT (Dependent Object Types) is an object calculus with path-dependent types and abstract type members, developed to serve as a theoretical foundation for the Scala programming language. As yet, DOT does not model all of Scala's features, but a small ...
Implementing higher-kinded types in Dotty
SCALA 2016: Proceedings of the 2016 7th ACM SIGPLAN Symposium on Scaladotty is a new, experimental Scala compiler based on DOT, the calculus of Dependent Object Types. Higher-kinded types are a natural extension of first-order lambda calculus, and have been a core construct of Haskell and Scala. As long as such types are ...
Implicit Parameters for Logic Programming
PPDP '18: Proceedings of the 20th International Symposium on Principles and Practice of Declarative ProgrammingImplicit parameters allow programmers to omit certain arguments from function calls and have them automatically inferred by the compiler based on their types. At every call site, the compiler determines the values of the implicit parameters based on ...






Comments