background preloader

Functional programming

Facebook Twitter

Jeff Erickson's Algorithms Course Materials. Www.cs.kent.ac.uk/people/staff/dat/miranda/whyfp90.pdf. Www.dreamsongs.com/NewFiles/WhyOfY.pdf. Why Why Functional Programming Matters Matters. Why Why Functional Programming Matters MattersI recently re-read the amazing paper Why Functional Programming Matters (“WhyFP”). Although I thought that I understood WhyFP when I first read it a few years ago, when I had another look last weekend I suddenly understood that I had missed an important message.1 Now obviously (can you guess from the title?) The paper is about the importance of one particular style of programming, functional programming. And when I first read the paper, I took it at face value: I thought, “Here are some reasons why functional programming languages matter.”

On re-reading it, I see that the paper contains insights that apply to programming in general. I don’t know why this surprises me. The fact is, programming language design revolves around program design. In a very real sense, the design of a programming language is a strong expression of the opinions of the designer about good programs. Can we add though subtraction? Is this obvious? Factoring That’s it. What haskell doesn't have. (but it does have fun!) At one point, someone on buzz was advocating haskell, and he pulled out the usual "look how elegant the fibonacci function looks! " thing. Someone else was doing the "the point must be productivity, and you can't prove it adds more productivity" thing.

I think the point is fun, not productivity. I wrote a big long response, but then felt like getting involved in a big language discussion on work time was kind of a waste of time, so didn't bother posting it. I know people like to pull out fibonacci and quicksort, but they don't seem all that compelling to me. Instead: Think about the whole thing with iterators or generators or whatever else that so many imperative languages have. Select vs. threads vs. coroutines is also gone, but that's just a ghc feature. Think about that whole null pointer thing that all these imperative languages have. Think about that whole thing with reference vs. values. Type casts are gone too. To me, the main compelling thing is *fun*.

Monads

Two Worlds: Functional Thinking after OO « Squirrel's. It goes without saying that functional programming is very different from object-oriented. While it may take a while to grasp, it turns out that functional programming can also lead to simpler, more robust, maintainable and testable solutions. The First Encounter In his classic “Clean Code” Robert C. Martin describes a great (and widely adopted) way to object oriented programming. It occurred to me it’s quite different from how the natural flow of functional programming in Clojure, where typically all users are below their dependencies. The light dawned when I came across Paul Graham’s essay titled “Programming Bottom-Up”. Language for the Problem Lisp (and Clojure) have minimal syntax.

As Paul writes, “you don’t just write your program down toward the language, you also build the language up toward your program. Simplicity and Abstractness Ending up with a language tailored for the problem is not the only nice feature of functional programming. Maintainability and Code Organization.