This is an interesting and difficult question. For some time, there has been a tendency for the concepts of functional languages to come into imperative languages, and the line between functional / imperative languages is quite blurred. For example, suppose you want to compose each element of the xs list and store the result in a new ys list.
>> xs = [1, 2, 3]
>> xs = [1, 2, 3] -- Haskell
If you did not know about functional idioms, you can do this:
>> ys = [0] * len(xs)
In Haskell, you just write
>> ys = map (\x -> x * x) xs -- Haskell
This idiom also exists in Python, of course
>> ys = map(lambda x: x * x, xs)
Perhaps an even more convenient way to write this is to use a list
>> ys = [x * x | x <- xs] -- Haskell
which also exists in python
>> ys = [x * x for x in xs]
Of course, the functional way is much nicer (and more complex, more reusable) than the imperative way. But in this case, you do not need to use a functional language for profit - you just need to be prepared to "think functionally."
source share