A way to mark functions as pure for this purpose would be great! Especially if it's not as fraught as const in C++.
A way to mark functions as pure for this purpose would be great! Especially if it's not as fraught as const in C++.
It was also a very, very long time ago, and so today's Rust might be different enough that those reasons don't apply any more.
Haskell can do cool optimizations that make it feel like magic sometimes.
Meanwhile mapping in Rust generally takes an iterator and produces another iterator that will apply the given closure to the current element as it's yielded. So the naive codegen for iter().map().map().map().collect() is exactly what list fusion is trying to produce -- no temporary lists.
TL;DR: making "map" having the monadic `T[U] -> T[V]` signature is really expensive. ¯\_(ツ)_/¯
Ah, yeah I had a vague memory that that was the case, which is why I asked.. I seem to recall it being removed, but I only follow Rust news, don't use it, so I wasn't sure of the reasons or implications.
You just demonstrated what I mean when I comment that const is fraught.
Purity is a different concept.
Purity more easily maps more closely to an abstract concept and is easier to for people reason about.