Affiliation:
1. Texas A&M University, College Station, TX, USA
Abstract
Selecting operations based on the run-time type of an object is key to many object-oriented and functional programming techniques. We present a technique for implementing open and efficient type switching on hierarchical extensible data types. The technique is general and copes well with C++ multiple inheritance. To simplify experimentation and gain realistic performance using production-quality compilers and tool chains, we implement a type switch construct as an ISO C++11 library, called Mach7. This library-only implementation provides concise notation and outperforms the visitor design pattern, commonly used for case analysis on types in object-oriented programming. For closed sets of types, its performance roughly equals equivalent code in functional languages, such as OCaml and Haskell. The type-switching code is easier to use and is more expressive than hand-coded visitors are. The library is non-intrusive and circumvents most of the extensibility restrictions typical of the visitor design pattern. It was motivated by applications involving large, typed, abstract syntax trees.
Publisher
Association for Computing Machinery (ACM)
Subject
Computer Graphics and Computer-Aided Design,Software
Reference56 articles.
1. Clang: a C language family frontend for LLVM. http://clang.llvm.org/ 2007. Clang: a C language family frontend for LLVM. http://clang.llvm.org/ 2007.
2. Liz: A System for Axiomatic Programming. http://liz.axiomatics.org/ 2012. Liz: A System for Axiomatic Programming. http://liz.axiomatics.org/ 2012.
3. Compiling a functional language