Abstract
Implicit functions are dependently typed functions, such that arguments are provided (by default) by inference machinery instead of programmers of the surface language. Implicit functions in Agda are an archetypal example. In the Haskell language as implemented by the Glasgow Haskell Compiler (GHC), polymorphic types are another example. Implicit function types are first-class if they are treated as any other type in the surface language. This holds in Agda and partially holds in GHC. Inference and elaboration in the presence of first-class implicit functions poses a challenge; in the context of Haskell and ML-like languages, this has been dubbed “impredicative instantiation” or “impredicative inference”. We propose a new solution for elaborating first-class implicit functions, which is applicable to full dependent type theories and compares favorably to prior solutions in terms of power, generality and simplicity. We build atop Norell’s bidirectional elaboration algorithm for Agda, and we note that the key issue is incomplete information about insertions of implicit abstractions and applications. We make it possible to track and refine information related to such insertions, by adding a function type to a core Martin-L'of type theory, which supports strict (definitional) currying. This allows us to represent undetermined domain arities of implicit function types, and we can decide at any point during elaboration whether implicit abstractions should be inserted.
Supplemental Material
- Andreas Abel. 2013. Normalization by Evaluation: Dependent Types and Impredicativity. Ph.D. Dissertation. LudwigMaximilians-Universität München. Habilitation thesis.Google Scholar
- Andreas Abel, Joakim Öhman, and Andrea Vezzosi. 2018. Decidability of conversion for type theory in type theory. Proc. ACM Program. Lang. 2, POPL ( 2018 ), 23 : 1-23 : 29. https://doi.org/10.1145/3158111 Google Scholar
Digital Library
- Andreas Abel and Brigitte Pientka. 2011. Higher-Order Dynamic Pattern Unification for Dependent Types and Records. In Typed Lambda Calculi and Applications-10th International Conference, TLCA 2011, Novi Sad, Serbia, June 1-3, 2011. Proceedings (Lecture Notes in Computer Science, Vol. 6690 ), C.-H. Luke Ong (Ed.). Springer, 10-26. https://doi.org/10.1007/ 978-3-642-21691-6_5 Google Scholar
Cross Ref
- Thorsten Altenkirch and Ambrus Kaposi. 2016. Type theory in type theory using quotient inductive types. In Proceedings of the 43rd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2016, St. Petersburg, FL, USA, January 20-22, 2016, Rastislav Bodik and Rupak Majumdar (Eds.). ACM, 18-29. https://doi.org/10.1145/2837614.2837638 Google Scholar
Digital Library
- Lars Birkedal, Ranald Clouston, Bassel Mannaa, Rasmus Ejlers Møgelberg, Andrew M. Pitts, and Bas Spitters. 2020. Modal dependent type theory and dependent right adjoints. Math. Struct. Comput. Sci. 30, 2 ( 2020 ), 118-138. https://doi.org/10. 1017/S0960129519000197 Google Scholar
Cross Ref
- Didier Le Botlan and Didier Rémy. 2003. MLF: raising ML to the power of system F. SIGPLAN Notices 38, 9 ( 2003 ), 27-38. https://doi.org/10.1145/944746.944709 Google Scholar
Digital Library
- Simon Boulier, Pierre-Marie Pédrot, and Nicolas Tabareau. 2017. The Next 700 Syntactical Models of Type Theory. In Proceedings of the 6th ACM SIGPLAN Conference on Certified Programs and Proofs (Paris, France) ( CPP 2017). ACM, New York, NY, USA, 182-194. https://doi.org/10.1145/3018610.3018620 Google Scholar
Digital Library
- Thierry Coquand. 1996. An Algorithm for Type-Checking Dependent Types. Sci. Comput. Program. 26, 1-3 ( 1996 ), 167-177. https://doi.org/10.1016/ 0167-6423 ( 95 ) 00021-6 Google Scholar
Digital Library
- Joshua Dunfield and Neelakantan R. Krishnaswami. 2013. Complete and easy bidirectional typechecking for higherrank polymorphism. In ACM SIGPLAN International Conference on Functional Programming, ICFP'13, Boston, MA, USA-September 25-27, 2013, Greg Morrisett and Tarmo Uustalu (Eds.). ACM, 429-442. https://doi.org/10.1145/2500365.2500582 Google Scholar
Digital Library
- Peter Dybjer. 1995. Internal Type Theory. In Types for Proofs and Programs, International Workshop TYPES'95, Torino, Italy, June 5-8, 1995, Selected Papers (Lecture Notes in Computer Science, Vol. 1158 ), Stefano Berardi and Mario Coppo (Eds.). Springer, 120-134. https://doi.org/10.1007/3-540-61780-9_66 Google Scholar
Cross Ref
- Richard A. Eisenberg. 2016. Dependent Types in Haskell: Theory and Practice. CoRR abs/1610.07978 ( 2016 ). arXiv: 1610.07978 http://arxiv.org/abs/1610.07978Google Scholar
- Richard A. Eisenberg, Stephanie Weirich, and Hamidhasan G. Ahmed. 2016. Visible Type Application. In Programming Languages and Systems-25th European Symposium on Programming, ESOP 2016, Held as Part of the European Joint Conferences on Theory and Practice of Software, ETAPS 2016, Eindhoven, The Netherlands, April 2-8, 2016, Proceedings (Lecture Notes in Computer Science, Vol. 9632 ), Peter Thiemann (Ed.). Springer, 229-254. https://doi.org/10.1007/978-3-662-49498-1_10 Google Scholar
Digital Library
- Adam Michael Gundry. 2013. Type inference, Haskell and dependent types. Ph.D. Dissertation. University of Strathclyde, Glasgow, UK. http://oleg.lib.strath.ac.uk/R/?func= dbin-jump-full&object_id=22728Google Scholar
- Robert Harper. 2016. Practical foundations for programming languages. Cambridge University Press.Google Scholar
Digital Library
- Marcus Johansson and Jesper Lloyd. 2015. Eliminating the problems of hidden-lambda insertion-Restricting implicit arguments for increased predictability of type checking in a functional programming language with depending types. Master's thesis. Chalmers University of Technology.Google Scholar
- Ambrus Kaposi, Simon Huber, and Christian Sattler. 2019. Gluing for Type Theory. In 4th International Conference on Formal Structures for Computation and Deduction, FSCD 2019, June 24-30, 2019, Dortmund, Germany (LIPIcs, Vol. 131 ), Herman Geuvers (Ed.). Schloss Dagstuhl-Leibniz-Zentrum für Informatik, 25 : 1-25 : 19. https://doi.org/10.4230/LIPIcs.FSCD. 2019.25 Google Scholar
Cross Ref
- Daan Leijen. 2008. HMF: simple type inference for first-class polymorphism. In Proceeding of the 13th ACM SIGPLAN international conference on Functional programming, ICFP 2008, Victoria, BC, Canada, September 20-28, 2008, James Hook and Peter Thiemann (Eds.). ACM, 283-294. https://doi.org/10.1145/1411204.1411245 Google Scholar
Digital Library
- Daan Leijen. 2009. Flexible types: robust type inference for first-class polymorphism. In Proceedings of the 36th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2009, Savannah, GA, USA, January 21-23, 2009, Zhong Shao and Benjamin C. Pierce (Eds.). ACM, 66-77. https://doi.org/10.1145/1480881.1480891 Google Scholar
Digital Library
- Daniel R. Licata, Ian Orton, Andrew M. Pitts, and Bas Spitters. 2018. Internal Universes in Models of Homotopy Type Theory. In 3rd International Conference on Formal Structures for Computation and Deduction, FSCD 2018, July 9-12, 2018, Oxford, UK (LIPIcs, Vol. 108 ), Hélène Kirchner (Ed.). Schloss Dagstuhl-Leibniz-Zentrum für Informatik, 22 : 1-22 : 17. https://doi.org/10.4230/LIPIcs.FSCD. 2018.22 Google Scholar
Cross Ref
- Dale Miller. 1991. A Logic Programming Language with Lambda-Abstraction, Function Variables, and Simple Unification. J. Log. Comput. 1, 4 ( 1991 ), 497-536. https://doi.org/10.1093/logcom/1.4. 497 Google Scholar
Cross Ref
- Aleksandar Nanevski, Frank Pfenning, and Brigitte Pientka. 2008. Contextual modal type theory. ACM Trans. Comput. Log. 9, 3 ( 2008 ), 23 : 1-23 : 49. https://doi.org/10.1145/1352582.1352591 Google Scholar
Digital Library
- Ulf Norell. 2007. Towards a practical programming language based on dependent type theory. Ph.D. Dissertation. Chalmers University of Technology.Google Scholar
- Steven Schäfer, Tobias Tebbi, and Gert Smolka. 2015. Autosubst: Reasoning with de Bruijn Terms and Parallel Substitutions. In Interactive Theorem Proving-6th International Conference, ITP 2015, Nanjing, China, August 24-27, 2015, Proceedings (Lecture Notes in Computer Science, Vol. 9236 ), Christian Urban and Xingyuan Zhang (Eds.). Springer, 359-374. https: //doi.org/10.1007/978-3-319-22102-1_24 Google Scholar
Cross Ref
- Alejandro Serrano, Jurriaan Hage, Simon Peyton Jones, and Dimitrios Vytiniotis. 2020. A quick look at impredicativity. (January 2020 ). https://www.microsoft.com/en-us/research/publication/a-quick-look-at-impredicativity/ In submission.Google Scholar
- Alejandro Serrano, Jurriaan Hage, Dimitrios Vytiniotis, and Simon Peyton Jones. 2018. Guarded impredicative polymorphism. In Proceedings of the 39th ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI 2018, Philadelphia, PA, USA, June 18-22, 2018, Jefrey S. Foster and Dan Grossman (Eds.). ACM, 783-796. https://doi.org/10. 1145/3192366.3192389 Google Scholar
Digital Library
- Jonathan Sterling. 2019. Algebraic Type Theory and Universe Hierarchies. CoRR abs/ 1902.08848 ( 2019 ). arXiv: 1902.08848 http://arxiv.org/abs/ 1902.08848Google Scholar
- The Univalent Foundations Program. 2013. Homotopy Type Theory: Univalent Foundations of Mathematics. https: //homotopytypetheory.org/book, Institute for Advanced Study.Google Scholar
- Dimitrios Vytiniotis, Simon L. Peyton Jones, Tom Schrijvers, and Martin Sulzmann. 2011. OutsideIn(X) Modular type inference with local assumptions. J. Funct. Program. 21, 4-5 ( 2011 ), 333-412. https://doi.org/10.1017/S0956796811000098 Google Scholar
Digital Library
- Dimitrios Vytiniotis, Stephanie Weirich, and Simon L. Peyton Jones. 2006. Boxy types: inference for higher-rank types and impredicativity. In Proceedings of the 11th ACM SIGPLAN International Conference on Functional Programming, ICFP 2006, Portland, Oregon, USA, September 16-21, 2006, John H. Reppy and Julia L. Lawall (Eds.). ACM, 251-262. https://doi.org/10.1145/1159803.1159838 Google Scholar
Digital Library
- Dimitrios Vytiniotis, Stephanie Weirich, and Simon L. Peyton Jones. 2008. FPH: first-class polymorphism for Haskell. In Proceeding of the 13th ACM SIGPLAN international conference on Functional programming, ICFP 2008, Victoria, BC, Canada, September 20-28, 2008, James Hook and Peter Thiemann (Eds.). ACM, 295-306. https://doi.org/10.1145/1411204.1411246 Google Scholar
Digital Library
- Pawel Wieczorek and Dariusz Biernacki. 2018. A Coq formalization of normalization by evaluation for Martin-Löf type theory. In Proceedings of the 7th ACM SIGPLAN International Conference on Certified Programs and Proofs, CPP 2018, Los Angeles, CA, USA, January 8-9, 2018, June Andronick and Amy P. Felty (Eds.). ACM, 266-279. https://doi.org/10.1145/3167091 Google Scholar
Digital Library
Index Terms
Elaboration with first-class implicit function types
Recommendations
Type inference for unboxed types and first class mutability
PLOS '06: Proceedings of the 3rd workshop on Programming languages and operating systems: linguistic support for modern operating systemsSystems programs rely on fine-grain control of data representation and use of state to achieve performance, conformance to hard-ware specification, and temporal predictability. The robustness and checkability of these programs could be greatly improved ...
Simple, partial type-inference for System F based on type-containment
Proceedings of the tenth ACM SIGPLAN international conference on Functional programmingWe explore partial type-inference for System F based on type-containment. We consider both cases of a purely functional semantics and a call-by-value stateful semantics. To enable type-inference, we require higher-rank polymorphism to be user-specified ...
Polymorphic type inference and abstract data types
Many statically typed programming languages provide an abstract data type construct, such as the module in Modula-2. However, in most of these languages, implementations of abstract data types are not first-class values. Thus, they cannot be assigned to ...






Comments