Reflecting Scala

Yohann Coppel. Reflecting Scala. Semester Project Report Laboratory for Programming Methods. Ecole Polytechnique Federale de Lausanne, Lausanne, Switzerland, January 2008.

Abstract

Object-oriented languages usually implement an API supporting metalevel operations such as reflection. However, reflection APIs generally do not follow the three design principle for reflection and meta-programming. These three principles specify that meta-level facilities must a) encapsulate their implementation (encapsulation); b) be separated from base-level functionality (stratification); and c) their ontology should correspond to the ontology of the language itself (ontological correspondence) . The Scala programming language does not have any specific API supporting meta-programming. However, since it is compiled into Java bytecode, it is compatible with the complete Java library. Consequently, one can use the Java reflection API in order to access meta-level informations about a Scala program. Anyhow, this approach presents important limitations and raises some usability problems. We introduce a new mirror based reflection API for the Scala programming language, following the three principles previously mentioned. This API also maintains an important separation between classes, seen as data structures, and types, more abstract elements.