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 条
  • [1] Multi-stage programming with functors and monads: Eliminating abstraction overhead from generic code
    Carette, J
    Kiselyov, O
    GENERATIVE PROGRAMMING AND COMPONENT ENGINEERING, PROCEEDINGS, 2005, 3676 : 256 - 274
  • [2] Multi-stage programming
    Taha, W
    Sheard, T
    ACM SIGPLAN NOTICES, 1997, 32 (08) : 321 - 321
  • [3] An ML-Style Module System for Cross-Stage Type Abstraction in Multi-stage Programming
    Suwa, Takashi
    Igarashi, Atsushi
    FUNCTIONAL AND LOGIC PROGRAMMING, FLOPS 2024, 2024, 14659 : 237 - 272
  • [4] A Generic Strategy for Multi-stage Stencils
    Bianco, Mauro
    Cumming, Benjamin
    EURO-PAR 2014 PARALLEL PROCESSING, 2014, 8632 : 584 - 595
  • [5] A gentle introduction to multi-stage programming
    Taha, W
    DOMAIN-SPECIFIC PROGRAM GENERATION, 2003, 3016 : 30 - 50
  • [6] Implicitly Heterogeneous Multi-Stage Programming
    Jason Eckhardt
    Roumen Kaiabachev
    Emir Pasalic
    Kedar Swadi
    Walid Taha
    New Generation Computing, 2007, 25 : 305 - 336
  • [7] Implicitly heterogeneous multi-stage programming
    Eckhardt, J
    Kaiabachev, R
    Pasalic, E
    Swadi, K
    Taha, W
    GENERATIVE PROGRAMMING AND COMPONENT ENGINEERING, PROCEEDINGS, 2005, 3676 : 275 - 292
  • [8] Refining semantics for multi-stage programming
    Ge, Rui
    Garcia, Ronald
    JOURNAL OF COMPUTER LANGUAGES, 2019, 51 : 222 - 240
  • [9] Refining Semantics for Multi-stage Programming
    Ge, Rui
    Garcia, Ronald
    PROCEEDINGS OF THE 16TH ACM SIGPLAN INTERNATIONAL CONFERENCE ON GENERATIVE PROGRAMMING: CONCEPTS AND EXPERIENCES (GPCE'17), 2017, : 2 - 14
  • [10] Implicitly heterogeneous multi-stage programming
    Eckhardt, Jason.
    Kaiabachev, Roumen
    Pasalic, Emir
    Swadi, Kedar
    Taha, Walid
    NEW GENERATION COMPUTING, 2007, 25 (03) : 305 - 336