2 ms·
Is the ST performance better or worse than the purely functional approach? It actually looks pretty good, not really any more verbose than Java to be honest.
by aetherspawn 9y ago
Is the ST performance better or worse than the purely functional approach? It actually looks pretty good, not really any more verbose than Java to be honest.
- chrisdone 9y agoDirect mutations for a mutating algorithm is certainly faster than rebuilding a data structure representing a set of variables. Most of the time. Though, there are exceptions where they're equivalent thanks to GHC's optimizations (e.g. splitting up a record's fields into n registers).
- Tarean 9y agoSome algorithms require mutation to have a decent time complexity and ST allows you to implement those. There is a tiny cost for each mutable memory location since the garbage collector has to work around then. A single array won't even be measurable, though. Also, there are some referentially transparent algorithms that can't be implemented via ST - like laziness.
- vaibhavsagar 9y agoThis might help answer your first question: https://medium.com/@jonathangfischoff/are-mutable-references-in-haskell-fast-f095f4144977 https://medium.com/@jonathangfischoff/are-mutable-references...