Iterators and Streams in Rust and Haskell
I find it really interesting that the idiomatic Haskell implementations (basically math) are the best-performing, while the Rust-like Haskell implementation (using an IORef) is orders of magnitude slower. This is exactly what I want: describe the logic of the operation, and leave the compiler to optimize for the hardware (in this case a CPU which mutates registers). The Rust implementation makes assumptions about the underlying hardware (has registers we can mutate), and is only about 15% faster than the Haskell implementation which makes no such assumptions.<p>In essence, this is why I love Haskell, and choose it over Rust: it allows me to write my application logic directly, without having to think about it in terms of mutation, and have the generated code be pretty fast. If GHC becomes well-optimized enough it can render Rust obsolete, since &quot;no runtime overhead&quot; becomes pretty meaningless if it&#x27;s actually slower than Haskell (e.g. using LinearTypes, which removes need for GC). Rust can&#x27;t render Haskell obsolete, however, since Haskell&#x27;s goal is basically allowing you to write logic directly, using types as propositions and values as proofs. So Haskell&#x27;s goal is a qualitative one (execute logic) while Rust&#x27;s is a quantitative one (performance&#x2F;no runtime overhead), which results in Haskell being able to take the place of Rust if GHC gains sufficiently in performance.