Multi-stage programming with functors and monads: Eliminating abstraction overhead from generic code

被引:20
|
作者
Carette, Jacques [1 ]
Kiselyov, Oleg [2 ]
机构
[1] McMaster Univ, Dept Comp & Software, Hamilton, ON L8S 4K1, Canada
[2] FNMOC, Monterey, CA 93943 USA
基金
加拿大自然科学与工程研究理事会;
关键词
MetaOCaml; Linear algebra; Genericity; Generative; Staging; Functor; Symbolic; LANGUAGES; SYSTEMS;
D O I
10.1016/j.scico.2008.09.008
中图分类号
TP31 [计算机软件];
学科分类号
081202 ; 0835 ;
摘要
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 extent - over 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. (C) 2008 Elsevier B.V. All rights reserved.
引用
收藏
页码:349 / 375
页数:27
相关论文
共 50 条
  • [31] A Gentle Introduction to Multi-stage Programming, Part II
    Taha, Walid
    GENERATIVE AND TRANSFORMATIONAL TECHNIQUES IN SOFTWARE ENGINEERING II, 2008, 5235 : 260 - 290
  • [32] CLOP: A Multi-stage Compiler to Seamlessly Embed Heterogeneous Code
    Makarov, Dmitri
    Hauswirth, Matthias
    ACM SIGPLAN NOTICES, 2016, 51 (03) : 109 - 112
  • [33] CLOP: A Multi-stage Compiler to Seamlessly Embed Heterogeneous Code
    Makarov, Dmitri
    Hauswirth, Matthias
    GPCE'15: PROCEEDINGS OF THE 2015 ACM SIGPLAN INTERNATIONAL CONFERENCE ON GENERATIVE PROGRAMMING: CONCEPTS AND EXPERIENCES, 2015, : 109 - 112
  • [34] CLOP: A multi-stage compiler to seamlessly embed heterogeneous code
    Makarov, Dmitri
    Hauswirth, Matthias
    ACM SIGPLAN Notices, 2015, 51 (03): : 109 - 112
  • [35] Multi-stage guided code generation for Large Language Models
    Han, Yewei
    Lyu, Chen
    ENGINEERING APPLICATIONS OF ARTIFICIAL INTELLIGENCE, 2025, 139
  • [36] Decision rules for information discovery in multi-stage stochastic programming
    Vayanos, Phebe
    Kuhn, Daniel
    Rustem, Berc
    2011 50TH IEEE CONFERENCE ON DECISION AND CONTROL AND EUROPEAN CONTROL CONFERENCE (CDC-ECC), 2011, : 7368 - 7373
  • [37] Two-stage linear decision rules for multi-stage stochastic programming
    Merve Bodur
    James R. Luedtke
    Mathematical Programming, 2022, 191 : 347 - 380
  • [38] Two-stage linear decision rules for multi-stage stochastic programming
    Bodur, Merve
    Luedtke, James R.
    MATHEMATICAL PROGRAMMING, 2022, 191 (01) : 347 - 380
  • [39] Randomized Progressive Hedging methods for multi-stage stochastic programming
    Gilles Bareilles
    Yassine Laguel
    Dmitry Grishchenko
    Franck Iutzeler
    Jérôme Malick
    Annals of Operations Research, 2020, 295 : 535 - 560
  • [40] Multi-stage reactive power programming using genetic algorithm
    Zhao, Xin
    Gao, Shan
    2008 THIRD INTERNATIONAL CONFERENCE ON ELECTRIC UTILITY DEREGULATION AND RESTRUCTURING AND POWER TECHNOLOGIES, VOLS 1-6, 2008, : 1484 - 1487