Attribute Grammars Fly First-Class How to do Aspect Oriented Programming in Haskell

被引:5
作者
Viera, Marcos [1 ]
Swierstra, S. Doaitse [2 ]
Swierstra, Wouter [3 ]
机构
[1] Univ Republica, Inst Computac, Montevideo, Uruguay
[2] Univ Utrecht, Dept Comp Sci, NL-3508 TB Utrecht, Netherlands
[3] Chalmers Univ Technol, S-41296 Gothenburg, Sweden
关键词
Design; Languages; Performance; Standardization; Attribute Grammars; Class system; Lazy evaluation; Type-level programming; Haskell; HList;
D O I
10.1145/1631687.1596586
中图分类号
TP31 [计算机软件];
学科分类号
081202 ; 0835 ;
摘要
Attribute Grammars (AGs), a general-purpose formalism for describing recursive computations over data types, avoid the trade-off which arises when building software incrementally: should it be easy to add new data types and data type alternatives or to add new operations on existing data types? However, AGs are usually implemented as a pre-processor, leaving e. g. type checking to later processing phases and making interactive development, proper error reporting and debugging difficult. Embedding AG into Haskell as a combinator library solves these problems. Previous attempts at embedding AGs as a domain-specific language were based on extensible records and thus exploiting Haskell's type system to check the well-formedness of the AG, but fell short in compactness and the possibility to abstract over oft occurring AG patterns. Other attempts used a very generic mapping for which the AG well-formedness could not be statically checked. We present a typed embedding of AG in Haskell satisfying all these requirements. The key lies in using HList-like typed heterogeneous collections (extensible polymorphic records) and expressing AG well-formedness conditions as type-level predicates (i.e., type-class constraints). By further type-level programming we can also express common programming patterns, corresponding to the typical use cases of monads such as Reader, Writer and State. The paper presents a realistic example of type-class-based type-level programming in Haskell.
引用
收藏
页码:245 / 256
页数:12
相关论文
共 27 条
[1]  
[Anonymous], 2003, The Fun of Programming
[2]  
Auerbacher I., 2009, CHILDREN TERROR
[3]   USING CIRCULAR PROGRAMS TO ELIMINATE MULTIPLE TRAVERSALS OF DATA [J].
BIRD, RS .
ACTA INFORMATICA, 1984, 21 (03) :239-250
[4]  
BOYLAND J, 2005, J ACM JACM, V52
[5]   Associated type synonyms [J].
Chakravarty, MMT ;
Keller, G ;
Jones, SP .
ACM SIGPLAN NOTICES, 2005, 40 (09) :241-253
[6]  
de Moor O, 2000, LECT NOTES COMPUT SC, V1799, P121
[7]  
de Moor O., 2000, INFORMATICA, V24
[8]  
DIJKSTRA A, 2004, LNCS, V3622
[9]  
DIJKSTRA A, 2007, IMPLEMENTATION FUNCT
[10]  
FOKKER J, 2008, LANGUAGE DESCRIPTION