TY - JOUR
T1 - Multi-stage programming with functors and monads
T2 - Eliminating abstraction overhead from generic code
AU - Carette, Jacques
AU - Kiselyov, Oleg
N1 - Funding Information:
We wish to thank Cristiano Calgano for his help in adapting camlp4 for use with MetaOCaml. Many helpful discussions with Walid Taha are very appreciated. The implementation of the monadic notation, perform, was joint work with Lydia van Dijk. We gratefully acknowledge numerous, helpful suggestions by the anonymous reviewers. The first author was supported in part by NSERC Discovery Grant RPG262084-03.
PY - 2011/5/1
Y1 - 2011/5/1
N2 - We use multi-stage programming, monads and Ocaml's advanced module system to demonstrate how to eliminate all abstraction overhead from generic programs, while avoiding any inspection of the resulting code. We demonstrate this clearly with Gaussian Elimination as a representative family of symbolic and numeric algorithms. We parameterize our code to a great extentover domain, input and permutation matrix representations, determinant and rank tracking, pivoting policies, result types, etc.at no run-time cost. Because the resulting code is generated just right and not changed afterward, MetaOCaml guarantees that the generated code is well-typed. We further demonstrate that various abstraction parameters (aspects) can be made orthogonal and compositional, even in the presence of name-generation for temporaries, and "interleaving" of aspects. We also show how to encode some domain-specific knowledge so that "clearly wrong" compositions can be rejected at or before generation time, rather than during the compilation or running of the generated code.
AB - We use multi-stage programming, monads and Ocaml's advanced module system to demonstrate how to eliminate all abstraction overhead from generic programs, while avoiding any inspection of the resulting code. We demonstrate this clearly with Gaussian Elimination as a representative family of symbolic and numeric algorithms. We parameterize our code to a great extentover domain, input and permutation matrix representations, determinant and rank tracking, pivoting policies, result types, etc.at no run-time cost. Because the resulting code is generated just right and not changed afterward, MetaOCaml guarantees that the generated code is well-typed. We further demonstrate that various abstraction parameters (aspects) can be made orthogonal and compositional, even in the presence of name-generation for temporaries, and "interleaving" of aspects. We also show how to encode some domain-specific knowledge so that "clearly wrong" compositions can be rejected at or before generation time, rather than during the compilation or running of the generated code.
KW - Functor
KW - Generative
KW - Genericity
KW - Linear algebra
KW - MetaOCaml
KW - Staging
KW - Symbolic
UR - http://www.scopus.com/inward/record.url?scp=79952622441&partnerID=8YFLogxK
UR - http://www.scopus.com/inward/citedby.url?scp=79952622441&partnerID=8YFLogxK
U2 - 10.1016/j.scico.2008.09.008
DO - 10.1016/j.scico.2008.09.008
M3 - Article
AN - SCOPUS:79952622441
VL - 76
SP - 349
EP - 375
JO - Science of Computer Programming
JF - Science of Computer Programming
SN - 0167-6423
IS - 5
ER -