Abstract
We give a C++ solution to the Expression Problem that takes a components-for-cases approach. Our solution is a C++ transliteration of how Lightweight Modular Staging solves the Expression Problem. It, furthermore, gives a C++ encoding to object algebras and object algebra interfaces. We use our latter encoding by tying its recursive knot as in Datatypes à la Carte.
This work is partially funded by the LightKone European H2020 Project under Grant Agreement No. 732505 and partially by the Belgian National Fund for Scientific Research (F.R.S.-FNRS).
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Notes
- 1.
If the guarantee was for dynamically constructed terms too, we would have called it strong static type safety.
- 2.
Although our codebase remains fully functional without that (using ordinary type parametrisation), we retain its usage here for enhanced readability.
- 3.
Integration of a Decentralised Pattern Matching.
- 4.
This is a paraphrase of the combinator taken from the online specification at the C++ Reference: https://en.cppreference.com/w/cpp/utility/variant/visit.
- 5.
Posted online by James Iry on Wed, 22/10/2008 at http://lambda-the-ultimate.org/node/1134.
- 6.
References
Bahr, P., Hvitved, T.: Compositional data types. In: Järvi, J., Mu, S.-C. (eds.) 7th WGP, Tokyo, Japan, pp. 83–94. ACM, September 2011
Bahr, P., Hvitved, T.: Parametric compositional data types. In: Chapman, J., Levy, P.B. (eds.) 4th MSFP. ENTCS, vol. 76, pp. 3–24, February 2012
Black, A.P.: The expression problem, gracefully. In: Sakkinen, M. (ed.) MASPEGHI@ECOOP 2015, pp. 1–7. ACM, July 2015
Canning, P., Cook, W.R., Hill, W., Olthoff, W., Mitchell, J.C.: F-bounded polymorphism for object-oriented programming. In: 4th FPCA, pp. 273–280, September 1989
Chlipala, A.: Parametric higher-order abstract syntax for mechanized semantics. In: Hook, J., Thiemann, P. (eds.) 13th ICFP, Victoria, BC, Canada, pp. 143–156, September 2008
Cook, W.R.: Object-oriented programming versus abstract data types. In: de Bakker, J.W., de Roever, W.P., Rozenberg, G. (eds.) REX 1990. LNCS, vol. 489, pp. 151–178. Springer, Heidelberg (1991). https://doi.org/10.1007/BFb0019443
Cook, W.R., Hill, W.L., Canning, P.S.: Inheritance is not Subtyping. In: 17th POPL, San Francisco, CA, USA, pp. 125–135. ACM (1990)
Ernst, E., Ostermann, K., Cook, W.R.: A virtual class calculus. In: Morrisett, J.G., Peyton Jones, S.L. (eds.) 33rd POPL, pp. 270–282. ACM, January 2006
Garrigue, J.: Code reuse through polymorphic variants. In: FSE, vol. 25, pp. 93–100 (2000)
Guttag, J.V., Horning, J.J.: The algebraic specification of abstract data types. Acta Inform. 10, 27–52 (1978)
Haeri, S.H.: Component-based mechanisation of programming languages in embedded settings. Ph.D. thesis, STS, TUHH, Germany, December 2014
Haeri, S.H., Keir, P.W.: Metaprogramming as a Solution to the Expression Problem, November 2019
Haeri, S.H., Keir, P.W.: Multiple dispatch using compile-time metaprogramming. Submitted to 16th ICTAC, November 2019
Haeri, S.H., Schupp, S.: Reusable components for lightweight mechanisation of programming languages. In: Binder, W., Bodden, E., Löwe, W. (eds.) SC 2013. LNCS, vol. 8088, pp. 1–16. Springer, Heidelberg (2013). https://doi.org/10.1007/978-3-642-39614-4_1
Haeri, S.H., Schupp, S.: Expression compatibility problem. In: Davenport, J.H., Ghourabi, F. (eds.) 7th SCSS. EPiC Comp., vol. 39, pp. 55–67. EasyChair, March 2016
Haeri, S.H., Schupp, S.: Integration of a decentralised pattern matching: venue for a new paradigm intermarriage. In: Mosbah, M., Rusinowitch, M. (eds.) 8th SCSS. EPiC Comp., vol. 45, pp. 16–28. EasyChair, April 2017
Hofer, C., Ostermann, K., Rendel, T., Moors, A.: Polymorphic embedding of DSLs. In: Smaragdakis, Y., Siek, J.G. (eds.) 7th GPCE, Nashville, TN, USA, pp. 137–148. ACM, October 2008
Kennedy, A., Russo, C.V.: Generalized algebraic data types and object-oriented programming. In: Johnson, R.E., Gabriel, R.P. (eds.) 20th OOPSLA, San Diego, CA, USA, pp. 21–40. ACM, October 2005
Meijer, E., Hutton, G.: Bananas in space: extending fold and unfold to exponential types. In: Williams, J. (ed.) 7th FPCA, La Jolla, California, USA, pp. 324–333. ACM, June 1995
Odersky, M., Zenger, M.: Independently extensible solutions to the expression problem. In: FOOL, January 2005
Odersky, M., Zenger, M.: Scalable component abstractions. In: 20th OOPSLA, San Diego, CA, USA, pp. 41–57. ACM (2005)
Oliveira, B.C.d.S.: Modular visitor components. In: Drossopoulou, S. (ed.) ECOOP 2009. LNCS, vol. 5653, pp. 269–293. Springer, Heidelberg (2009). https://doi.org/10.1007/978-3-642-03013-0_13
Oliveira, B.C.d.S., Cook, W.R.: Extensibility for the masses - practical extensibility with object algebras. In: Noble, J. (ed.) ECOOP 2012. LNCS, vol. 7313, pp. 2–27. Springer, Heidelberg (2012). https://doi.org/10.1007/978-3-642-31057-7_2
Oliveira, B.C.d.S., Moors, A., Odersky, M.: Type classes as objects and implicits. In: Cook, W.R., Clarke, S., Rinard, M.C. (eds.) 25th OOPSLA, pp. 341–360. ACM, October 2010
Oliveira, B.C.d.S., Mu, S.-C., You, S.-H.: Modular reifiable matching: a list-of-functors approach to two-level types. In: Lippmeier, B. (ed.) 8th Haskell, pp. 82–93. ACM, September 2015
Oliveira, B.C.d.S., van der Storm, T., Loh, A., Cook, W.R.: Feature-oriented programming with object algebras. In: Castagna, G. (ed.) ECOOP 2013. LNCS, vol. 7920, pp. 27–51. Springer, Heidelberg (2013). https://doi.org/10.1007/978-3-642-39038-8_2
Ostermann, K.: Dynamically composable collaborations with delegation layers. In: Magnusson, B. (ed.) ECOOP 2002. LNCS, vol. 2374, pp. 89–110. Springer, Heidelberg (2002). https://doi.org/10.1007/3-540-47993-7_4
O’Sullivan, B., Goerzen, J., Stewart, D.: Real World Haskell: Code You Can Believe in. O’Reilly, Sebastopol (2008)
Pressman, R.S.: Software Engineering: A Practitioner’s Approach, 7th edn. McGraw-Hill, New York (2009)
Rendel, T., Brachthäuser, J.I., Ostermann, K.: From object algebras to attribute grammars. In: Black, A.P., Millstein, T.D. (eds.) 28th OOPSLA, pp. 377–395. ACM, October 2014
Reynolds, J.C.: User-defined types and procedural data structures as complementary approaches to type abstraction. In: Schuman, S.A. (ed.) New Direc. Algo. Lang., pp. 157–168. INRIA (1975)
Rompf, T., Odersky, M.: Lightweight modular staging: a pragmatic approach to runtime code generation and compiled DSLs. In: 9th GPCE, Eindhoven, Holland, pp. 127–136. ACM (2010)
Sommerville, I.: Software Engineering, 9th edn. Addison-Wesley, Reading (2011)
Swierstra, W.: Data types à la Carte. JFP 18(4), 423–436 (2008)
Torgersen, M.: The expression problem revisited. In: Odersky, M. (ed.) ECOOP 2004. LNCS, vol. 3086, pp. 123–146. Springer, Heidelberg (2004). https://doi.org/10.1007/978-3-540-24851-4_6
Vandevoorde, D., Josuttis, N.M., Gregor, D.: C++ Templates: The Complete Guide, 2nd edn. Addison Wesley, Reading (2017)
Wadler, P.: The Expression Problem. Java Genericity Mailing List, November 1998
Wang, Y., Oliveira, B.C.d.S.: The expression problem, Trivially! In: 15th MODULARITY, pp. 37–41. ACM, New York (2016)
Zenger, M., Odersky, M.: Extensible algebraic datatypes with defaults. In: 6th ICFP, pp. 241–252, Florence, Italy. ACM (2001)
Author information
Authors and Affiliations
Corresponding author
Editor information
Editors and Affiliations
A C++ Features Used
A C++ Features Used
A C++ (or ) can be type parameterised. The below, for example, takes two type parameters and :
Likewise, C++ functions can take type parameters:
From C++20 onward, certain type parameters need not to be mentioned explicitly. For example, the above function can be abbreviated as:
A ( or non- ) can define nested type members. For example, the below defines to be :
Nested types can themselves be type parameterised, like :
C++17 added as a type-safe representation for unions. An instance of , at any given time, holds a value of one of its alternative types. That is, the static type of such an instance is that of the it is defined with; whilst, the dynamic type is one and only one of those alternative types. As such, a function that is to be applied on a needs to be applicable to its alternative types. Technically, a visitor is required for the alternative types. The function , takes a visitor in addition to a pack of arguments to be visited.
The variable above is bound to a \(\lambda \)-abstraction that, given an , returns its value times two. \(\lambda \)-abstractions can also capture unbound names. In such a case, the captured name needs to be mentioned in the opening square brackets before the list of parameters. For example, the \(\lambda \)-abstraction below captures the name :
Rights and permissions
Copyright information
© 2019 Springer Nature Switzerland AG
About this paper
Cite this paper
Haeri, S.H., Keir, P. (2019). Solving the Expression Problem in C++, á la LMS. In: Hierons, R., Mosbah, M. (eds) Theoretical Aspects of Computing – ICTAC 2019. ICTAC 2019. Lecture Notes in Computer Science(), vol 11884. Springer, Cham. https://doi.org/10.1007/978-3-030-32505-3_20
Download citation
DOI: https://doi.org/10.1007/978-3-030-32505-3_20
Published:
Publisher Name: Springer, Cham
Print ISBN: 978-3-030-32504-6
Online ISBN: 978-3-030-32505-3
eBook Packages: Computer ScienceComputer Science (R0)