Why functional programming matters — Mary Sheeran & John Hughes

Who needs booleans or integers, says John. We can use functions instead! Integers are just for counting loops anyway.

If we want to add two numbers now, we can just sequence loops:

We can continue this for ever, there is no stopping John, everything can be replaced by functions. These are called Church Encodings and can  apply to any other datastructures. A bit later, Peter Landin coined the idea of ‘laws’ for programming languages, like map f (reverse l)) === (reverse (map f))

Mary now introduces a paper by Turing award winner Backus (which we should all read) starting with:

“Conventional languages are getting bigger but not stronger. Inherent defects make them fat and weak” Wow! That is harsh John!

In this talk Mary is going to talk about 3 of those inherent weaknesses.

• Focus on Word at a time.
• Because of their origin in the von Neumann Style, languages were too much concerned with the lower level of data
• Inability to effectively use powerful small constructs to build bigger ones
• They lacked, what we would now call higher-order functions
• Lack of useful mathematical properties for reasoning about programs
• This goes back to the laws of Landin, can we express that the inproduct can be calculated in two different ways (this is the example he gives in the paper)

Mary’s PhD supervisor Peter Henderson worked on creating Escher like pictures with software by combining transformations of one basic fish by and rotating and scaling them.

From Henderson’s Functional Geometry paper

Again here there were laws, like rot(above(p,q) = beside (rot(p), rot(q))

He said: “There are many more rules of this sort. It seems there is a positive correlation between the simplicity of the rules and the quality of the algebra as a description tool.”

If you want to try something like this, try Pan or have a look at this F# implementation.

In the 90’s there was a study funded by Darpa comparing Haskell, Ada, C++ and Awk in terms of programmer productivity. One of the first empirical studies, I guess. Participants had to program a 2D mapping and they compared lines of code, docs and development time.

First DARPA did not believe the results, as the Haskell solution was made by Mark Jones himself and he would of course be very good at it. So they recruited a PhD student (line (10) in the figure) taught him Haskell and his solution was second smallests! So Haskell is better. Was DARPA impressed. Not really.

They were convinced it was incomplete because it did not address issues such as data structure design and execution order. The other kind of response had more to do with the ‘cleverness’ of the solution. One of the evaluators described the Haskell prototype as being ‘too cute for its own good’.

1 Comment

1. Bethany Saint

Stop it! Just stop it with these posts. It’s been a few years now that we’ve been seeing how great functional languages are. In that time the exact opposite of functional languages, Go, was released and hundreds of practical applications using Go now exist. Even though most every “languages person” out there hates it.

Time to put up or shut up. Start creating compelling applications written in Haskell (or whatever) that sit on my desktop or in my browser and are things I will use every day. Stop TELLING us how good functional languages are and start SHOWING us.