ABSTRACT
The MetaML approach for multi-stage programming provides the static guarantee of type safety and scope safety for generated code, regardless of the values of static parameters. Modules are indispensable to build large-scale programs in ML-like languages, however, they have a performance problem. To solve this problem, several languages proposed recently allow one to generate ML-style modules. Unfortunately, those languages had the problems of limited expressiveness, incomplete proofs, and code explosion.
This paper proposes two-stage programming languages for module generation, which solve all the above issues. Our languages accommodate two styles: first-class modules with generative functors and second-class modules with applicative functors. Module generation in both styles is shown to have their own merits by concrete examples. We present type systems, and type-preserving translations from our languages to plain MetaOCaml. We also show the results of performance measurements, which confirms the effectiveness of our languages.
Supplemental Material
- Cristiano Calcagno, Eugenio Moggi, and Walid Taha. 2004. ML-Like Inference for Classifiers. In Programming Languages and Systems, 13th European Symposium on Programming, ESOP 2004, Held as Part of the Joint European Conferences on Theory and Practice of Software, ETAPS 2004, Barcelona, Spain, March 29 - April 2, 2004, Proceedings, David A. Schmidt (Ed.) (Lecture Notes in Computer Science, Vol. 2986). Springer, 79–93. https://doi.org/10.1007/978-3-540-24725-8_7 Google ScholarCross Ref
- 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 (2009), 509–543. https://doi.org/10.1017/S0956796809007205 Google ScholarDigital Library
- Rowan Davies. 1996. A Temporal-Logic Approach to Binding-Time Analysis. In Proceedings, 11th Annual IEEE Symposium on Logic in Computer Science, New Brunswick, New Jersey, USA, July 27-30, 1996. 184–195. https://doi.org/10.1109/LICS.1996.561317 Google ScholarCross Ref
- Derek Dreyer. 2005. Understanding and Evolving the ML Module System. Ph.D. Dissertation. USA. isbn:0542015501 AAI3166274.Google Scholar
- Sebastian Erdweg and Klaus Ostermann. 2017. A Module-System Discipline for Model-Driven Software Development. Art Sci. Eng. Program., 1, 2 (2017), 9. https://doi.org/10.22152/programming-journal.org/2017/1/9Google ScholarCross Ref
- Xavier Leroy et al.. 2019. Chapter 21. Optimisation with Flambda. The OCaml system release 4.09. https://caml.inria.fr/pub/docs/manual-ocaml/flambda.htmlGoogle Scholar
- Matthew Flatt. 2013. Submodules in racket: you want it when, again? In Generative Programming: Concepts and Experiences, GPCE’13, Indianapolis, IN, USA - October 27 - 28, 2013, Jaakko Järvi and Christian Kästner (Eds.). ACM, 13–22. https://doi.org/10.1145/2517208.2517211 Google ScholarDigital Library
- Yuichiro Hanada and Atsushi Igarashi. 2014. On Cross-Stage Persistence in Multi-Stage Programming. In Functional and Logic Programming - 12th International Symposium, FLOPS 2014, Kanazawa, Japan, June 4-6, 2014. Proceedings, Michael Codish and Eijiro Sumii (Eds.) (Lecture Notes in Computer Science, Vol. 8475). Springer, 103–118. https://doi.org/10.1007/978-3-319-07151-0_7 Google ScholarCross Ref
- Jun Inoue, Oleg Kiselyov, and Yukiyoshi Kameyama. 2016. Staging beyond terms: prospects and challenges. In Proceedings of the 2016 ACM SIGPLAN Workshop on Partial Evaluation and Program Manipulation, PEPM 2016, St. Petersburg, FL, USA, January 20 - 22, 2016. 103–108. https://doi.org/10.1145/2847538.2847548 Google ScholarDigital Library
- Oleg Kiselyov. 2014. The Design and Implementation of BER MetaOCaml - System Description. In Functional and Logic Programming - 12th International Symposium, FLOPS 2014, Kanazawa, Japan, June 4-6, 2014. Proceedings. 86–102. https://doi.org/10.1007/978-3-319-07151-0_6 Google ScholarCross Ref
- Xavier Leroy. 1995. Applicative Functors and Fully Transparent Higher-Order Modules. In Proceedings of the 22nd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’95). Association for Computing Machinery, New York, NY, USA. 142–153. isbn:0897916921 https://doi.org/10.1145/199448.199476 Google ScholarDigital Library
- Lionel Parreaux and Amir Shaikhha. 2020. Multi-Stage Programming in the Large with Staged Classes. In Proceedings of the 19th ACM SIGPLAN International Conference on Generative Programming: Concepts and Experiences (GPCE 2020). Association for Computing Machinery, New York, NY, USA. 35–49. isbn:9781450381741 https://doi.org/10.1145/3425898.3426961 Google ScholarDigital Library
- Lionel Parreaux, Amir Shaikhha, and Christoph E. Koch. 2017. Squid: type-safe, hygienic, and reusable quasiquotes. In Proceedings of the 8th ACM SIGPLAN International Symposium on Scala, SCALA@SPLASH 2017, Vancouver, BC, Canada, October 22-23, 2017, Heather Miller, Philipp Haller, and Ondrej Lhoták (Eds.). ACM, 56–66. https://doi.org/10.1145/3136000.3136005 Google ScholarDigital Library
- Gabriel Radanne, Thomas Gazagnaire, Anil Madhavapeddy, Jeremy Yallop, Richard Mortier, Hannes Mehnert, Mindy Preston, and David J. Scott. 2019. Programming Unikernels in the Large via Functor Driven Development. CoRR, abs/1905.02529 (2019), arxiv:1905.02529. arxiv:1905.02529Google Scholar
- Yuhi Sato, Yukiyoshi Kameyama, and Takahisa Watanabe. 2020. Module generation without regret. In Proceedings of the 2020 ACM SIGPLAN Workshop on Partial Evaluation and Program Manipulation, PEPM@POPL 2020, New Orleans, LA, USA, January 20, 2020, Casper Bach Poulsen and Zhenjiang Hu (Eds.). ACM, 1–13. https://doi.org/10.1145/3372884.3373160 Google ScholarDigital Library
- Tim Sheard. 1998. Using MetaML: A Staged Programming Language. In Advanced Functional Programming, Third International School, Braga, Portugal, September 12-19, 1998, Revised Lectures, S. Doaitse Swierstra, Pedro Rangel Henriques, and José Nuno Oliveira (Eds.) (Lecture Notes in Computer Science, Vol. 1608). Springer, 207–239. https://doi.org/10.1007/10704973_5 Google ScholarCross Ref
- Walid Taha. 2003. A Gentle Introduction to Multi-stage Programming. In Domain-Specific Program Generation, International Seminar, Dagstuhl Castle, Germany, March 23-28, 2003, Revised Papers. 30–50. https://doi.org/10.1007/978-3-540-25935-0_3 Google ScholarCross Ref
- Walid Taha and Michael Florentin Nielsen. 2003. Environment Classifiers. SIGPLAN Not., 38, 1 (2003), Jan., 26–37. issn:0362-1340 https://doi.org/10.1145/640128.604134 Google ScholarDigital Library
- Walid Taha and Tim Sheard. 1997. Multi-Stage Programming. In Proceedings of the 1997 ACM SIGPLAN International Conference on Functional Programming (ICFP ’97), Amsterdam, The Netherlands, June 9-11, 1997, Simon L. Peyton Jones, Mads Tofte, and A. Michael Berman (Eds.). ACM, 321. https://doi.org/10.1145/258948.258990 Google ScholarDigital Library
- Takahisa Watanabe and Yukiyoshi Kameyama. 2018. Program generation for ML modules (short paper). In Proceedings of the ACM SIGPLAN Workshop on Partial Evaluation and Program Manipulation, Los Angeles, CA, USA, January 8-9, 2018. 60–66. https://doi.org/10.1145/3162072 Google ScholarDigital Library
- Jeremy Yallop. 2016. Staging generic programming. In Proceedings of the 2016 ACM SIGPLAN Workshop on Partial Evaluation and Program Manipulation, PEPM 2016, St. Petersburg, FL, USA, January 20 - 22, 2016. 85–96. https://doi.org/10.1145/2847538.2847546 Google ScholarDigital Library
Index Terms
- Type-safe generation of modules in applicative and generative styles
Recommendations
Module generation without regret
PEPM 2020: Proceedings of the 2020 ACM SIGPLAN Workshop on Partial Evaluation and Program ManipulationModules are an indispensable mechanism for providing abstraction to programming languages. To reduce the abstraction overhead in the usage of modules, Watanabe et al. proposed a language for generating and manipulating code of modules, and implemented ...
Program generation for ML modules (short paper)
PEPM '18: Proceedings of the ACM SIGPLAN Workshop on Partial Evaluation and Program ManipulationProgram generation has been successful in various domains which need high performance and high productivity. Yet, programming-language supports for program generation need further improvement. An important omission is the functionality of generating ...
Making legacy Fortran code type safe through automated program transformation
AbstractFortran is still widely used in scientific computing, and a very large corpus of legacy as well as new code is written in FORTRAN 77. In general this code is not type safe, so that incorrect programs can compile without errors. In this paper, we ...
Comments