Skip to content

Functional Programming in 2012 … time to learn something more?

2012 August 9

Functional programming ideas have been around longer than computers: Church’s lambda-calculus was invented in the 1930s as a way of describing computations as functions around the same time that Turing was describing what an idealised (human) “computer” could do through Turing machines. The idea of using functions as the primary means of computing fed straight into Lisp and its (LAMBDA …), ideas of procedures in Algol68, but settled into what people now call functional languages in the late 1980s, with the definition of ML, Haskell and Erlang.

Erlang – which is really a language for high-concurrency, fault-tolerant, robust systems – is based on functional ideas because it’s so much easier to write concurrent systems when every assignment is a single assignment (check out Single Assignment C too). Haskell and ML (and also OCaml, SML, …) are general purpose languages where types do much of the heavy lifting for you: types are inferred from what you write, and if you have got a program that type checks then you’ve ironed out a whole class of errors before running a single instruction.

As I’ve said, these languages were first defined more than twenty years ago, so what are the modern functional programming languages? One answer is Java, and other mainstream languages, which are taking on more and more functional features. Using immutable data is inherited from the functional world, as were Java generics. Coming soon are closures – yes, that’s right, LAMBDA in Java! So you can do functional programming in Java (and O’Reilly have recently published Functional Programming for Java Developers: Tools for Better Concurrency, Abstraction, and Agility).

But what if you want to try the real thing? A first choice is F#, which puts a functional language into the .NET framework as a first-class citizen, with internationalization, intellisense, and full integration with C# and the .NET libraries. One of the ways of getting started with F# is to use it to explore some of the library APIs, executing calls interactively. Extending Java to give a fuller functional language, as well as Erlang-style concurrency, is Scala. From Scala too, there’s access to the Java libraries, as well as execution on the JVM. Finally, it’s worth taking a look at Haskell, which is functional first, but which provides controlled access to concurrency, IO, exceptions and a wealth of open source libraries.

At CUFP 2012 you can find tutorials on F#, Scala (1 day each) and Haskell (2 days) designed to give you an introduction to the functional style of programming even if you’ve never used a functional language, this is a chance to find out more.

But, why bother, you might say? One reason is sheer curiosity: you’ll find out what all the fuss is about, and see where ideas like map-reduce come naturally out of the programming style. It also give you a different way of attacking problems: even if you’re going to be programming in Java, then a functional style might well give you a different tool to solve the problem at hand.

Another reason is to get a job (really!). How are functional languages getting used? Erlang and Scala support high-throughput message handling and web systems, and are the “secret weapon” behind applications supporting Facebook, Amazon and other systems. Haskell gets used in building domain-specific languages in security, crypto and increasingly in the financial sector, where F# is getting traction too. You’ll see a steady stream of jobs calling for Erlang, Haskell, Scala, F#, as well as for people who are happy using one of these languages and C, or Java or whatever, because functional languages often come in as a solution to part of a problem, rather than solving the whole thing.

If you like the sound of this, then sign up for one of the tutorials at CUFP, and I look forward to seeing you there!

My main research interests are in functional programming, most recently to help people to write programs more effectively. In particular, together with Huiqing Li I have been working on building refactoring tools for functional programs in Erlang and Haskell, supported by EU and EPSRC funding. I have also worked in reasoning and multimedia. I have written four books on Functional Programming including Erlang Programming with Francesco Cesarini and Haskell: the Craft of Functional ProgrammingSimon Thompson, Professor of Logic and Computation, University of Kent

 

6 Responses Post a comment
  1. avatar
    Antoni permalink
    October 5, 2012

    Have you seen this post?

    It is a Closure implementation for Java 5, 6 and 7.

    It looks pretty neat, and works really well.

    http://mseifed.blogspot.se/2012/09/closure-implementation-for-java-5-6-and.html

  2. avatar
    Guillermo permalink
    August 10, 2012

    I don´t see C# in any comment, just as a helper for F#,
    and C# has closure and close-to functional programming parts thanks to LinQ
    Which is part of any .NET language rigth now.

  3. avatar
    August 9, 2012

    Java moves towards closures since years, and I doubt it will ever get them. So the current status is, that Java developers can only scratch the surface of functional programming using its parts (e.g. writing predicates using Google Guava library). However, even such thing can be a real mind-opening experience!

  4. avatar
    August 9, 2012

    Don’t forget Clojure, a LISP (and therefore) functional JVM language that can integrate with Java.

    • avatar
      August 10, 2012

      There’s also a half-day tutorial on Clojure at CUFP given by Lau Jensen and Karl Krukow … I was concentrating on the full day events, but we’ve also got four half day tutorials on Clojure, OCaml, and two on the web and functional programming (Haskell, Erlang): http://cufp.org/conference/schedule

Trackbacks & Pingbacks

  1. Making a programming language: Part 4 – Hello World | My programming escapades

Leave a Reply to Guillermo Cancel reply