3 ms·
Well your second example relies for speed and efficiency on Haskell being lazy. If you did e.g. a map -> filter -> sum chain, the performance is not that great
by teh64 4y ago
Well your second example relies for speed and efficiency on Haskell being lazy. If you did e.g. a map -> filter -> sum chain, the performance is not that great without lazy evaluation guaranteed by Haskell's implementation, which can complicate code in other scenarios or in the complexity of the compiler. OCaml is also an FP language, and the second example would be almost the same text, but with much worse performance.
Also, Python is an OOP language, but a simple map implementation there is not much more verbose:
def map(function, items):
if len(items) != 0:
return [function(items[0]), *map(function, items[1:])]
return []
- epgui 4y agoI think the more pythonic way would probably be to use a list comprehension: def map(f, items): return [f(i) for i in items] These differences are all more about specific languages than about FP per se, however.
- teh64 4y agoTrue, but I tried to make it as close to the Haskell example as possible. I just think the OOP -> verbose/complex argument is really annoying, especially if it applies mostly to Java code.
- epgui 4y agoEither way, in both our examples, what we wrote was very much in a functional style, and Haskell also uses list comprehensions. The only thing unique about the Haskell example, I think, was pattern-matching... And while that's nice, you don't really need that for FP.