3 ms·
Sure. What I meant is that while python does have first-class functions, you don't make much use of it in idiomatic style. Much of the logic is still encapsulat
by ozataman 14y ago
Sure. What I meant is that while python does have first-class functions, you don't make much use of it in idiomatic style. Much of the logic is still encapsulated in bloated, less flexible classes and/or imperative style variables you create to hold middle values.
If you wanted to use first-class functions in your code pervasively, then you lack the massive libraries and compiler optimizations available to Haskell. As a result, first-class functions are only used at a superficial level in Python, perhaps as key arguments to some functions.
In a language like Haskell, on the other hand, you make use of the first-class nature of functions all the time.
It's common to have pipelines like:
foldr step 0 . map convert . concatMap (chunks 2) $ inputList
where
step = ...
convert = ...
Almost everything in that pipeline takes a function as a parameter. Also note how chunks takes an integer, partially applying the function, and returns a new function that is now ready to take a list to chunk into groups of 2. You really get used to this stuff.
- icebraining 14y agoThanks. Yes, I can definitively see the benefits in having a stdlib and compiler that follows a functional approach.