8 ms·
> Purely functional algorithms and data structures are typically slower. Functional persistent data structures bring many advantages, even to imperative progra
by willtim 7y ago
> Purely functional algorithms and data structures are typically slower.
Functional persistent data structures bring many advantages, even to imperative programmers. For example, if your text editor used a persistent data structure, it probably wouldn't need to lock you out during a save and would support better undo.
Mutation is efficient, but comes with many drawbacks, especially when state is shared or provenance is required. This is why functional data structures and ideas are appearing outside of functional programming, for example ZFS, git, Blockchain, Spark, Kafka etc etc
> Imperative code is also more concise than equivalent functional code.
This couldn't be further from the truth. Just as Fortran liberated arithmetic expressions from the verbosity of imperative programming, FP allows us to move beyond non-compositional word-at-time sequences of mutation commands and build much higher-level abstractions. Modern imperative languages have borrowed many ideas from FP, but are still no way near as expressive as e.g. Haskell. Of course, imperative programming is still very useful and that's why Haskell has good support for it.
- h91wka 7y ago> This couldn't be further from the truth. In imperative languages you don't need Edward Kmett to invent lenses for you.
- willtim 7y agoLenses are not necessary to practice FP, just sometimes useful (and Edward didn't invent them). Try updating a deeply nested record in your favourite imperative language without mutating the original (!)