|
ABSTRACT
It is often hard to write programs that are efficient yet reusable. For example, an efficient implementation of Gaussian elimination should be specialized to the structure and known static properties of the input matrix. The most profitable optimizations, such as choosing the best pivoting or memoization, cannot be expected of even an advanced compiler because they are specific to the domain, but expressing these optimizations directly makes for ungainly source code. Instead, a promising and popular way to reconcile efficiency with reusability is for a domain expert to write code generators. Two pillars of this approach are types and effects. Typed multilevel languages such as MetaOCaml ensure _safety_: a well-typed code generator neither goes wrong nor generates code that goes wrong. Side effects such as state and control ease correctness: an effectful generator can resemble the textbook presentation of an algorithm, as is familiar to domain experts, yet insert let for memoization and if for bounds-checking, as is necessary for efficiency. However, adding effects blindly renders multilevel types unsound. We introduce the first two-level calculus with control effects and a sound type system. We give small-step operational semantics as well as a continuation-passing style (CPS) translation. For soundness, our calculus restricts the code generator's effects to the scope of generated binders. Even with this restriction, we can finally write efficient code generators for dynamic programming and numerical methods in direct style, like in algorithm textbooks, rather than in CPS or monadic style.
REFERENCES
Note: OCR errors may be found in this Reference List extracted from the full text article. ACM has opted to expose the complete List rather than only correct and linked references.
| |
1
|
Asai, Kenichi, and Yukiyoshi Kameyama. 2007. Polymorphic delimited continuations. In APLAS, 239--254. LNCS 4807.
|
 |
2
|
|
| |
3
|
|
| |
4
|
|
| |
5
|
Carette, Jacques, and Oleg Kiselyov. 2008. Multi-stage programming with functors and monads: Eliminating abstraction overhead from generic code. Science of Computer Programming.
|
| |
6
|
Albert Cohen , Sébastien Donadio , Maria-Jesus Garzaran , Christoph Herrmann , Oleg Kiselyov , David Padua, In search of a program generator to implement generic transformations for high-performance computing, Science of Computer Programming, v.62 n.1, p.25-46, September 2006
[doi> 10.1016/j.scico.2005.10.013]
|
| |
7
|
Czarnecki, Krzysztof, John T. O'Donnell, Jörg Striegnitz, and Walid Taha. 2004. DSL implementation in MetaOCaml, Template Haskell, and C++. In DSPG 2003, 51--72. LNCS 3016.
|
| |
8
|
Danvy, Olivier, and Andrzej Filinski. 1989. A functional abstraction of typed contexts. Tech. Rep. 89/12, DIKU, University of Copenhagen, Denmark. http://www.daimi.au.dk/~danvy/Papers/fatc.ps.gz.
|
 |
9
|
|
| |
10
|
Danvy, Olivier. 1992. Representing control: A study of the CPS transformation. Mathematical Structures in Computer Science 2(4): 361--391.
|
| |
11
|
|
| |
12
|
Eckhardt, Jason, Roumen Kaiabachev, Emir Pašalic, Kedar N. Swadi, and Walid Taha. 2005. Implicitly heterogeneous multistage programming. In GPCE, 275--292. LNCS 3676.
|
 |
13
|
|
| |
14
|
|
 |
15
|
|
| |
16
|
Frigo, Matteo, and Steven G. Johnson. 2005. The design and implementation of FFTW3. Proceedings of the IEEE 93(2):216--231.
|
| |
17
|
Gomard, Carsten K., and Neil D. Jones. 1991. A partial evaluator for the untyped lambda calculus. Journal of Functional Programming 1(1):21--69.
|
| |
18
|
|
 |
19
|
|
| |
20
|
Kiselyov, Oleg. 2006. Native delimited continuations in (byte-code) OCaml. http://okmij.org/ftp/Computation/Continuations.html#caml-shift.
|
 |
21
|
|
| |
22
|
Kiselyov, Oleg, and Walid Taha. 2005. Relating FFTW and split-radix. In ICESS, 488--493. LNCS 3605.
|
 |
23
|
|
| |
24
|
Lengauer, Christian, and Walid Taha, eds. 2006. Special issue on the 1st MetaOCaml workshop (2004), vol. 62(1) of Science of Computer Programming.
|
 |
25
|
|
| |
26
|
McAdam, Bruce J. 2001. Y in practical programs. Workshop on fixed points in computer science; http://www.dsi.uniroma1.it/~labella/absMcAdam.ps.
|
| |
27
|
MetaOCaml. 2006. MetaOCaml. http://www.metaocaml.org.
|
| |
28
|
Michie, Donald. 1968. "Memo" functions and machine learning. Nature 218:19--22.
|
| |
29
|
|
 |
30
|
|
| |
31
|
|
| |
32
|
|
| |
33
|
Pušchel, Emir, Walid Taha, and Tim Sheard. 2002. Tagless staged interpreters for typed languages. In ICFP, 157--166.
|
| |
34
|
Peyton Jones, Simon L. 2003. The Haskell 98 language and libraries. Journal of Functional Programming 13(1):1--255.
|
| |
35
|
Pušchel, Markus, José M. F. Moura, Jeremy Johnson, David Padua, Manuela Veloso, Bryan W. Singer, Jianxin Xiong, Franz Franchetti, Aca Gačić, Yevgen Voronenko, Kang Chen, Robert W. Johnson, and Nick Rizzolo. 2005. SPIRAL: Code generation for DSP transforms. Proceedings of the IEEE 93(2): 232--275.
|
| |
36
|
Sørensen, Morten Heine B., Robert Glück, and Neil D. Jones. 1994. Towards unifying deforestation, supercompilation, partial evaluation, and generalized partial computation. In ESOP, 485--500. LNCS 788.
|
| |
37
|
|
| |
38
|
Swadi, Kedar, Walid Taha, and Oleg Kiselyov. 2005. Dynamic programming benchmark. http://www.metaocaml.org/examples/dp/
|
 |
39
|
|
 |
40
|
|
| |
41
|
Taha, Walid. 2005. Resource-aware programming. In ICESS, 38--43. LNCS 3605.
|
 |
42
|
|
| |
43
|
Talpin, Jean-Pierre, and Pierre Jouvelot. 1992. Polymorphic type, region and effect inference. Journal of Functional Programming 2(3):245--271.
|
 |
44
|
|
| |
45
|
|
| |
46
|
Thiemann, Peter, and Dirk Dussart. 1999. Partial evaluation for higher-order languages with state. http://www.informatik.uni-freiburg.de/~thiemann/papers/mlpe.ps.gz.
|
| |
47
|
Wadler, Philip L. 1992. Comprehending monads. Mathematical Structures in Computer Science 2(4):461--493.
|
|