In which scenarios should I consider a functional programming languages better suited to do a given task? Besides the so recently popular multicore problem of parallel programming.
Anything that involves creating sequence of derived data elements using a number of transformation steps.
Essentially, the "spreadsheet problem". You have some initial data and set of row-by-row calculations to apply to that data.
Our production applications do a number of statistical summaries of data; this is all best approached functionally.
One common thing we do is a match-merge between three monstrous data sets. Similar to a SQL join, but not as generalized. This is followed by a number of calculations of derived data. This is all just functional transformations.
The application is written in Python, but is written in a functional style using generator functions and immutable named tuples. It's a composition of lower-level functions.
Here's a concrete example of a functional composition.
for line in ( l.split(":") for l in ( l.strip() for l in someFile ) ):
print line[0], line[3]
This is one way that functional programming influences languages like Python.
Sometimes this kind of thing gets written as:
cleaned = ( l.strip() for l in someFile )
split = ( l.split(":") for l in cleaned )
for line in split:
print line[0], line[3]
If I decided to switch to a functional programming language which do you consider are the biggest pitfalls that I will face? (Besides the paradigm change and the difficulty to evaluate performance due to lazy evaluation).
Immutable objects is the toughest hurdle.
Often you'll wind up calculating values that create new objects instead of updating existing objects. The idea that it's a mutable attribute of an object is a hard mental habit to break.
A derived property or method function is a better approach. Stateful objects are a hard habit to break.
With so many functional programming languages out there, how would you choose the one the better suit your needs?
It doesn't matter at first. Pick any language to learn. Once you know something, you're in a position consider picking another to better suit your needs.
I've read up on Haskell just to understand the things Python lacks.
Best Answer
Since you write that you're a .NET developer and you don't even mention F#, odds are that you're a C# developer. In that case, I'd strongly suggest that you learn F# first. It's another .NET language, and it's a great stepping stone for anyone coming from C#.
In itself, it's a great FP language, but it also offers full interoperability with the existing .NET ecosystem. Besides its FP features, it also offers a full set of OOP features. This enables you to learn gradually.
for
loops with those.You can take each of these steps in small increments, all the time staying productive.
Once you have a good grasp of the functional parts of F#, Haskell can be a good next step. I've met many people who tried to learn Haskell 'from scratch'. Most people report that they give up because the learning curve is too steep.
I came to Haskell via some years of F# and found it a natural next step.
There's lots of free learning resources for F#, the most famous of which is probably F# for fun and profit. If you come from C#, another great introduction to F# is Real-World Functional Programming. It juxtaposes examples in C# and F# so that you can compare.
As far as I can tell, there aren't a lot of jobs where you get to program exclusively in F# or Haskell, but learning either will likely still make you a better programmer, so I'd highly recommend it.
I've written F# professionally, but never Haskell. I've written a lot of Haskell semi-professionally; I'm self-employed and invest significant time in doing so, but no-one has ever paid me to program in it. Still, I consider it highly worthwhile.