~ICMC 2015 - Sept. 25 - Oct. 1, 2015 - CEMI, University of North Texas Media Modules: Intermedia Systems in a Pure Functional Paradigm Mark Santolucito Yale University mark.santolucito@yale.edu Donya Quick Yale University donya.quick@yale.edu Paul Hudak Yale University paul.hudak@yale.edu ABSTRACT We present a Haskell-based architecture to efficiently and easily build systems utilizing many types of media. Haskell's pure functional paradigm is an increasingly popular programming style and is well-suited to many media manipulation tasks. However; intermedia systems are difficult to build due to foundational concepts of the pure functional paradigm and vast syntactic differences between many of Haskell's libraries. We use a new approach termed "media modules" for creating intermedia systems with increased modularity and parallelism. Finally, we demonstrate the use of this architecture in a variety of musically relevant scenarios. 1. INTRODUCTION In building systems to explore and integrate various types of digital media, the subsystems to process sound, user input, and other media types often become entangled. While media processes should be closely intertwined in concept, in many cases it is beneficial to separate media types at the implementation level. For example, it is not uncommon that the best programming style to write a user interface may be different than the best style to express a music processing algorithm. Unfortunately, some programming languages do not make this separation easy. Modularity and encapsulation are important principles of programming that are facilitated by many imperative, objectoriented languages. Design patterns such as Model-ViewController cleanly capture many interactive programs and enhance code reusability in imperative languages such as Java and C++. However, these sorts of object-oriented patterns do not fit well into more pure functional languages like Haskell due to the extreme differences in language paradigms. As a pure functional language, Haskell[1] excels at representing problems in ways that closely mirror their underlying mathematical structures, often allowing much more concise representations than would be possible in other languages. This concision directly translates to development speed and system stability[2]. The language's pure functional nature also predisposes it to using flat data parallelism, enabling Copyright: ~2015 Mark Santolucito et al. This is an open-access article distributed under the terms of the Creative Commons Attribution License 3.0 Unported, which permits unrestricted use, distribution, and reproduction in any medium, provided the original author and source are credited. maximum parallelization, and ensuring deadlock-free execution of a task with little manual modification. However, Haskell has historically found difficultly in the interactive domain. Recent work in the field of Functional Reactive Programming[3] has begun to ameliorate this issue, but it is not without lingering problems. In particular, our work addresses the issue of building intermedia systems in Haskell. There are many libraries in Haskell for various types of media manipulation, but they do not all work together. This is because many Haskell libraries can be thought of as domain specific embedded languages, or DSELs. Haskell DSELs can be exceedingly different in syntax and style to both other libraries and to the underlying Haskell programming language. This leads to problems when trying to use multiple DSELs in conjunction with each other, as the type systems and syntax can be so discrepant that there is no simple way to integrate the two. Because of this, it is common for users to become "trapped" in a particular DSEL once committing to using it. This can make the design and implementation of intermedia systems a slow and challenging process when features are needed from more than one DSEL, something a modern language should not require of programmers. We present an architecture using media modules to achieve flexibility through abstraction and clarity through isolation that overcomes these problems in Haskell. Each media module can be independently designed with regard to only an abstraction (a data specification) of the other modules, which both increases code reusability and overall modularity of the program. In some respects, this is similar to the way that abstract classes are used in an object-oriented setting, allowing some parallels to commonly used design patterns for interactive systems. With this approach, simple and effective parallelism becomes obvious and easy to implement, which has fundamental benefits beyond performance. For music processing, we provide examples utilizing a recently released Haskell library called Euterpea[4], which belongs to the Functional Reactive Programming paradigm. By using media modules, we then integrate this library with two graphical libraries, Elerea[5] and UISF[6]. Our architecture makes these libraries easy to use together, a task that is otherwise laborious and error-prone. Although our work is specific to functional programming, it addresses general problems familiar to both the computer music and programming languages communities. It is similar to the system in Max[7] and PureData[8] that is used to call foreign functions in languages like C and Supercollider[9]. Max - 376 -
Top of page Top of page