Metaprogramming manipulates abstract code that declares code to be generated. When a compiler encounters those instructions, it produces additional code at compile time. This can make a codebase more expressive and flexible, but the generated code is embedded implicitly and can be difficult to inspect. Use it carefully, especially when understanding what code will actually run matters. section 2.1.2
Metaprogramming
Metaprogramming is the manipulation or generation of program representations to produce or transform code, often during compilation.
How Functional Design and Architecture: Examples in Haskell covers it
- How deep it goes
- Defines abstract-code manipulation and compile-time generation, then cautions that generated output can be difficult to inspect.
- What you can do after
- Evaluate metaprogramming as a design tool while accounting for the difficulty of inspecting generated code.
- How it connects
- Connects abstract-code manipulation to compilers, which generate additional code at compile time.
Also explained in
-
The Joy of JavaScriptMetaprogramming is the practice of writing programs that inspect, generate, or modify other programs or their own structure.
-
Write Powerful Rust MacrosMetaprogramming is the practice of writing code that treats other code as data so it can manipulate or generate code or add capabilities.
Compare how 3 books explain metaprogramming →
Related concepts
- callbackuses · A callback is a function or other callable supplied or registered with a component for invocation at a specified event, condition, or point in execution.
- macroincludes · A macro is a named language construct or command sequence that expands into code or actions, often during preprocessing or compilation.
- reflectionuses · Reflection is a programming-language or runtime capability that lets a program inspect or manipulate its own types, structure, values, or metadata during execution.
This explainer was generated by Manning's knowledge graph from the text of Functional Design and Architecture: Examples in Haskell. The section links point to the parts of the book it draws on.


