Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do any functional languages support divide-and-conquer natively?

I'm sorry that I couldn't figure out a way to express the question more clearly in the headline, but essentially, it's this: almost all functional languages have constructs that allow you to process a variable list of arguments through tail recursion, as in this Erlang-ish pseudocode that sums up a list of numbers:

sumup(0,A) -> A.
sumup(N,A) -> sumup(N) + A.

However, one of the big appeals of functional languages to me is their inherent parallelism. And even though a problem such as summing up a list of numbers is obviously quite parallelizable, and would almost certainly be most efficiently handled by divide-and-conquer, I'm not aware of language features that make this a natural way to program. In fact, unless the language has features that allow reading the number of arguments based to a function and retrieving arguments based on index, I don't see how one could do it. Do any functional languages have features to encourage divide-and-conquer programming?

like image 234
afeldspar Avatar asked Feb 20 '10 00:02

afeldspar


1 Answers

Do any functional languages have features to encourage divide-and-conquer programming?

Yes: the ability to create new higher-order functions in libraries.

One of the most important such functions, on lists anyway, is foldr, which can be parallelized in principle when applied to an associative operator, although this is rarely done in practice. Why? Because foldr is designed around sequential data flow.

The beauty of functional languages is that once this problem is recognized, we can address the problem not by introducing new language features, but by making more intelligent use of the features we already have. To see how, look at Guy Steele's talk from August 2009, where he explains why foldr is not the right library function for parallel functional programming, and he proposes

  • A new programming style
  • A new representation of lists
  • New higher-order functions for libraries

that are all designed to support divide-and-conquer programming.

What I found so exciting about this talk is that it is not necessary to introduce new language features to support divide-and-conquer programming "natively". It is enough to take the primitives we already have and to use them to design better libraries.

If you have access to the ACM Digital library you can see video of Guy's talk Organizing Functional Code For Parallel Execution, or as Ben Karel points out, you can see video taken by Malcom Wallace on Vimeo.

like image 158
Norman Ramsey Avatar answered Oct 17 '22 13:10

Norman Ramsey