I never got much past dabbling a bit in Haskell. But learning about functional programming (FP), the importance of types, lazy evaluation, and declarative programming more generally really changed how I approached programming in any language.

Previously I (along with much of the computing industry in the 1990s) had been kind of taken with object oriented programming (OOP). In OOP there is a similar attention to types, but things get kind of weird when it comes to how those types get used and orchestrated.

Functional programming starts with the very simple idea of functions which have a name, can take arguments, and return a value. Functions can use other functions within them. Functions can be composed together, where the return value of one becomes an argument for another. Things gets really interesting because in FP languages like Haskell functions are themselves values. This means that functions can take other functions as arguments, and can also return functions.

The difference between FP and OOP gets a bit blurry when you consider that values and functions are sorts of objects. FP languages can implement OOP, as in the Common Lisp Object System. But in FP objects arent’t the center of attention, they are incidental to the operation of functions. I think FP concepts helped me design software because functions do things whereas objects are. In OOP you try to design the correct hierarchy of object types (classes) thinking that it will help your program work if it’s a good model of what you need to do. But in FP you focus on the different transformations of data that need to happen. It’s almost like the philosophical change in perspective that comes from seeing the world less as a set of objects to be manipulated and more like a set of interrelated processes in motion.

Anyway, all this is a digression because I started this post only wanting to say that as much as I’ve liked learning about Haskell I never really used it in any programming projects. But I have used software written in Haskell before, most notably the amazing Pandoc. I wrote my dissertation in Markdown, and have written articles in Markdown, even this blog uses Pandoc to generate references. I’ve come to appreciate how Markdown frees me from a choice of editor, and lets me focus on the words. But it wouldn’t be possible without a tool like Pandoc that makes it easy to combine my Markdown text with a database of my citations, and generate PDF and Word Documents (sometimes EPUBs) and a host of other formats I haven’t fully taken advantage of.

One remarkable thing about Pandoc is it has felt very stable over the years. It does this one thing (document conversion and generation) very well, and it hasn’t wavered. As I’ve perused the documentation I’ve often caught myself wondering as a side thought, who is this jgm? But until today I haven’t looked him up.

It gives me such pleasure to know that jgm is John MacFarlane, a philosophy professor at the University of California at Berkeley, who studies the history and philosophy of logic. Of course he does. It makes me wonder how much of the stability of Pandoc I experienced as a user comes from the FP approach to software development that Haskell provides. Another John, John Backus, famously said in his 1977 Turing Award lecture (Backus, 2007) that FP offers a new more sustainable approach to computation:

Conventional programming languages are growing ever more enormous, but not stronger. Inherent defects at the most basic level cause them to be both fat and weak: their primitive word-at-a-time style of programming inherited from their common ancestor–the von Neumann computer, their close coupling of semantics to state transitions, their division of programming into a world of expressions and a world of statements, their inability to effectively use powerful combining forms for building new programs from existing ones, and their lack of useful mathematical properties for reasoning about programs. An alternative functional style of programming is founded on the use of combining forms for creating programs. Functional programs deal with structured data, are often nonrepetitive and nonrecursive, are hierarchically constructed, do not name their arguments, and do not require the complex machinery of procedure declarations to become generally applicable. Combining forms can use high level programs to build still higher level ones in a style not possible in conventional languages.

I don’t know if Pandoc is a good example of this or not. But with 345 contributors and 13,578 commits (and counting) it’s hard not to see it as a quiet open source software success story. Now I want to read one of Professor MacFarlane’s books :)

References

Backus, J. (2007). Can programming be liberated from the von neumann style?: A functional style and its algebra of programs. In ACM Turing Award lectures. Association for Computing Machinery. https://doi.org/10.1145/1283920.1283933