Abstract
The preprocessor of the C language provides a standard way to generate code at compile time. However, writing and understanding these macros is difficult. Lack of typing, statelessness and uncommon syntax are the main reasons of this difficulty. Haskell is a high-level purely functional language with expressive type system, algebraic data types and many useful language extensions. These suggest that Haskell code can be written and maintained easier than preprocessor macros. Functional languages have certain similarities to macro languages. By using these similarities this paper describes a transformation that translates lambda expressions into preprocessor macros. Existing compilers for functional languages generate lambda expressions from the source code as an intermediate representation. As a result it is possible to write Haskell code that will be translated into preprocessor macros that manipulate source code. This may result in faster development and maintenance of complex macro metaprograms.
Keywords
MSC
68-N15
Cite this article
@article{cai-3380,
author = {Boldizsár Németh and Máté Karácsony and Zoltán Kelemen and Máté Tejfel},
title = {Defining C Preprocessor Macro Libraries with Functional Programs},
journal = {Computing and Informatics},
volume = {35},
number = {4},
pages = {819--851},
year = {2016},
issn = {1335-9150},
url = {https://cai.type.sk/content/2016/4/defining-c-preprocessor-macro-libraries-with-functional-programs/}
}
TY - JOUR AU - Boldizsár Németh AU - Máté Karácsony AU - Zoltán Kelemen AU - Máté Tejfel TI - Defining C Preprocessor Macro Libraries with Functional Programs JO - Computing and Informatics VL - 35 IS - 4 SP - 819 EP - 851 PY - 2016 SN - 1335-9150 UR - https://cai.type.sk/content/2016/4/defining-c-preprocessor-macro-libraries-with-functional-programs/ KW - C preprocessor KW - functional programming KW - Haskell KW - program transformation KW - transcompiler ER -
Németh, B., Karácsony, M., Kelemen, Z., & Tejfel, M. (2016). Defining C Preprocessor Macro Libraries with Functional Programs. Computing and Informatics, 35(4), 819–851. https://cai.type.sk/content/2016/4/defining-c-preprocessor-macro-libraries-with-functional-programs/