Alex Rivera | Logout

What are some problems best/worst addressed by functional programming?

Asked 2009-06-15T21:43:06.427
42

I've often heard that functional programming solves a lot of problems that are difficult in procedural/imperative programming. But I've also heard that it isn't great at some other problems that procedural programming is just naturally great at.

Before I crack open my book on Haskell and dive into functional programming, I'd like at least a basic idea of what I can really use it for (outside the examples in the book). So, what are those things that functional programming excels at? What are the problems that it is not well suited for?

Update

I've got some good answers about this so far. I can't wait to start learning Haskell now--I just have to wait until I master C :)

Reasons why functional programming is great:

  • Very concise and succinct -- it can express complex ideas in short, unobfuscated statements.
  • Is easier to verify than imperative languages -- good where safety in a system is critical.
  • Purity of functions and immutability of data makes concurrent programming more plausible.
  • Well suited for scripting and writing compilers (I would appreciate to know why though).
  • Math related problems are solved simply and beautifully.

Areas where functional programming struggles:

  • Debatable: web applications (though I guess this would depend on the application).
  • Desktop applications (although it depends on the language probably, F# would be good at this wouldn't it?).
  • Anything where performance is critical, such as game engines.
  • Anything involving lots of program state.
Edit
Report

3 Answers

6

Functional programming would be good for parallel programming. The fact that you're not relying on state changes with functional programming means that the various processors/cores won't step on eachother. So the types of algorithms that take well to parallelism like compression, graphical effects, and some complex mathematical tasks would also typically be good candidates for functional programming. And the fact that multi-core CPU's and GPU's are only growing in popularity also means that the demand for this type of thing will grow.

answered 2009-06-15T22:08:23.807
4

I find Haskell as well-suited for doing anything math-related. Not that this an actual professional project, but I made a sudoku solver and poker analyzer with it. Having a program that is mathematically provable is great.

As far as what it's not well-suited for is anything where performance is a priority. You have less control over the algorithms used, since it's more declarative than imperative.

answered 2009-06-15T22:17:07.500
2

I would say that functional programming will have trouble for the low-level stuff, operating system kernels, device drivers, etc.

I said "have trouble", not "cannot be used" (because of Turing equivalence, anything can be used for anything).

An interesting question is whether this problem is fundamental in functional programming (because physical devices have state) or if we can imagine systems-oriented functional programming language/environments. For instance, BitC is only partially functional (it relies a lot on mutability).

answered 2009-06-18T11:15:50.647

Your Answer