views:

589

answers:

7

I'm getting a bit tired of having to code explicitly for multicore if I want more speed, particularly when I'm just writing a one-off script. My dev box already has 8 cores and that number is going up a lot faster than the clock speed. Functional languages seem to offer a potential escape hatch, but I haven't put in the effort to master one of them yet.

I'd love to see some sample chunks of real-world code that are much better and/or more parallelizable than non-functional alternatives. I'm not picky about the language -- I'm more interested in the concepts.

Thanks!

+4  A: 

How about MapReduce? It's incredibly parallelizable and even though it's not implemented in functional languages as far as the paper goes, it's inspired by Lisp's map and reduce.

Chris Bunch
And Hadoop, MapReduce's open source alternative.
Yuval F
+2  A: 

Your question is asking for material right at the state of the art. I think your best introduction to this field, with examples, is the book Implicit Parallel Programming in pH by Nikhil and Arvind.

Norman Ramsey
+1  A: 

There's an extended example of a text indexer/searcher using mapreduce in Chapter 20 ("Programming Multi-core CPUs") of Programming Erlang. I don't know how impressive that is, but it looks like code mortals can write.

Darius Bacon
+3  A: 

This (long, but very good) video gives both an intro to F# and a compelling demo of how easy it is to parallelize code in the language:

http://channel9.msdn.com/pdc2008/TL11/

Brian
That was a great video -- thanks.
twk
A: 

LINQ is a nice example of functional programming in mainstream languages. Reified code and monads? In MY C#? :) Anyways, w.r.t. threading, there's mention of Parallel LINQ. By using immutability and higher order functions (and Expression, perhaps), libraries can parallelize things for us.

And another link to F# with async workflows. What's impressive is the ability to take sync code, and with a few small annotations turn it into async code. The code retains a lot of the imperative qualities you might be using. You don't have to completely change things to take advantage of this; the compiler via handles it all.

MichaelGG
A: 

Purely Functional Data Structures (long PDF), by Chris Okasaki.

Craig Stuntz
A: 

A teacher of mine used to joke that the greatest example of functional code is the code that is not written.

Anonymous