Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
264 views
in Technique[技术] by (71.8m points)

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

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.
question from:https://stackoverflow.com/questions/998552/what-are-some-problems-best-worst-addressed-by-functional-programming

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Functional programming excels at succinctness, owing to the existence of higher level functions (map, lfold, grep) and type inference.

It is also excellent at generic programming, for the same reasons, and that further increases the ability to express complex ideas in a short statement without obfuscation.

I appreciate these properties since they make interactive programming plausible. (e.g. R, SML).

I suspect that functional programming can also be verified more readily that other programming approaches, which is advantageous in safety critical systems (Nuclear Power Stations and Medical Devices).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...