Haskell and Music: Expressing Notes, Signals, and Symphonies in Haskell
Paul Hudak has written a new work on using Haskell for musical expression, entitled The Haskell School of Music — From Signals to Symphonies (Version 2.0).
Too often, titles on computer programming end up being dry publications that merely describe the syntax and semantics of a programming language without explaining any inspirational ideas for it. However, Hudak is able to motivate the study of Haskell with concepts from other fields that focus on the school of expression unique to the language.
Similarly to Hudak’s other work, The Haskell School of Expression — Learning Functional Programming through Multimedia  (nicknamed in the Haskell community as “SoE“), this book uses concepts from another field, in this case, music, to motivate the exploration of Haskell. Whereas SoE uses concepts from multimedia, SoM (a possible nickname for this new work) uses concepts from music.
The new work is written in an inspirational manner. On page xiv of the preface, Hudak describes the background for writing the book as follows:
I have also had a long, informal, yet passionate interest in music, being an amateur jazz pianist and having played in several bands over the years….
This current book is a rewrite of The Haskell School of Expression with a focus on computer music, based on, and greatly improving upon, the ideas in Haskore and HasSound.
Hudak used to play as a pianist in a jazz group based in New Haven, Connecticut, known as “Collectively Speaking.” I remember having attended one of their performances in New Haven in circa 1995 (Hudak was generous enough to greet me after the performance).
One of the interesting aspects of this work is that it is written from the perspective of appreciating music as an artistic medium for expression in Haskell. On page 1 of chapter 1, Hudak writes:
Computers are everywhere. And so is music! Although some might think of the two as being at best distant relatives, in fact they share many deep properties. Music comes from the soul, and is inspired by the heart, yet it has the mathematical rigor of computers. Computers have mathematical rigor of course, yet the most creative ideas in mathematics and computer science come from the soul, just like music.
The cover image of the book is one of “Euterpe, the Greek Muse of Music” (page i). Hudak describes the image on page 2 of chapter 1 as follows:
The core musical ideas are collected into a Haskell library called Euterpea. The name “Euterpea” is derived from “Euterpe,” who was one of the nine Greek muses, or goddesses of the arts, specifically the muse of music. A hypothetical picture of Euterpe graces the cover of this textbook.
In reading the above paragraph, I was somehow reminded of another book that, somewhat similarly, discusses the muse in the computer. In the work The Muse in the Machine: Computerizing the Poetry of Human Thought , David Gelernter, also a professor of computer science at Yale University, discusses the roles of emotion and spirituality in cognitive science. On pages 1-2 of chapter 1 of the work, Gelernter writes as follows:
It’s hard to conceive offhand of a less promising consumer innovation than a computer that comes factory equipped with “emotions”–but here’s a candidate: how about a “spiritual” computer? The spiritual computer spends its time pondering the mysteries of the universe, occasionally printing cryptic messages on its screen and otherwise ignoring the user altogether….
Who needs this kind of nonsense from a computer? Science does; in a broader sense we all do, because adding “emotions” to computers is the key to the biggest unsolved intellectual puzzle of our time: how thinking works.
However, whereas Gelernter’s outlook was based on poetry, Hudak’s is based on music. Nevertheless, the two works do share a common thread in being concerned with a form of art in relation to computers. On Chapter 1, page 4, Hudak writes:
In the area of computer music, there is another reason why clarity is important: namely, that the code often represents the author’s thought process, musical intent, and artistic choices. A conventional musical score does not say much about what the composer thought as she wrote the music, but a program often does. So when you write your programs, write them for others to see, and aim for elegance and beauty, just like the musical result that you desire.
The notion of the importance of art as a form of expression with respect to computers, although often ignored, is not new. A few years ago, Hudak helped to create a Computing and the Arts major at Yale. Prior to that, in 1997, a professor of cognitive science at Indiana University at Bloomington, Douglas R. Hofstadter, published a book discussing the problems of translating poetry and the implications of such issues for artificial intelligence, entitled Le Ton beau de Marot: In Praise of the Music of Language .
However, Hudak’s current work is unique in focusing on music as a mode of expression for functional programming in Haskell. With regard to this topic, Hudak writes on page 2 of chapter 1 as follows:
A dimension that proves particularly useful with respect to a programming language is one that separates high-level musical concerns from low-level musical concerns. Since a “high-level” programming language—namely Haskell—is used to program at both of these musical levels, to avoid confusion the terms note level and signal level will be used in the musical dimension.
From what I have read so far (I have just started reading the book), Hudak apparently plans to use functional abstraction to distinguish between musical concerns at different levels.
On a personal note, I have always been interested in how to use computers as a medium of expression for emotion. I occasionally write English haiku poetry in my spare time. Many years ago, in circa 1982, I attended a computer show at the Shinjuku Sankaku (Triangle) Building in Shinjuku, Tokyo, where I had the opportunity to witness an Apple ][ j-plus computer playing music using a musical organ-like keyboard. When notes were played on the keyboard, colored bars would appear on a nearby monitor, and the bars would increase or decrease in size depending on how long the keys were pressed. I used to play the violin in elementary school, and for some reason, remember being mesmerized as I watched the colored bars move up and down in tune with the music played on the keyboard. This may have been one reason that I have continually been interested in various forms of multimedia as a mode of expression using computers.
Sadly, during my college years (1989-1994, including a 1-year LOA), I did not have much opportunity to explore the role of multimedia in expression.
Art is useful for training the mind to appreciate beauty in computer science. While the syntax and semantics of Haskell are based on the beauty of concise functional expressions, beauty in writing an elegant computer program can be cultivated by exposure to haiku poetry, and beauty in musical expression can be cultivated by appreciating classical and jazz music. Greater exposure to beauty in art can help to cultivate a richer sense of beauty in computer science, which can, in turn, help in creating more elegant and innovative ideas.
More importantly, art can be a great motivator. Art is what takes the doldrums out of a mundane existence. Without art, computer science becomes a mere skill. Art lies at the base of innovation, which lies at the base of ingenuity. Ultimately, we are all artists in some form.
 Hudak, Paul. The Haskell School of Expression — Learning Functional Programming through Multimedia. New York: Cambridge University Press, 2000. Print.
 Gelernter, David Hillel. The Muse in the Machine: Computerizing the Poetry of Human Thought. New York: Simon & Schuster, 1994. Print.
 Hofstadter, Douglas R. Le Ton beau de Marot: In Praise of the Music of Language. New York: Basic Books, 1997. Print.