3 ms·
Actually, I think what you're really asking for is the ability to write sequential code and have the compiler work out if it could be parallel. It's true that
by moomin 13y ago
Actually, I think what you're really asking for is the ability to write sequential code and have the compiler work out if it could be parallel. It's true that the reducers implementation runs in parallel, but the API is actually agnostic.
Reducers also provide higher level constructs like filter, map, cat (concatenate), take-while, and of course reduce.
- lazyjones 13y ago> what you're really asking for is the ability to write sequential code and have the compiler work out if it could be parallel Not really. I don't care how I have to specify the desired computation, as long as it isn't excessively verbose and doesn't require me to nail down implementation details I don't care about - for example, a for-loop (from 1 to 1 million as in the accumulator example) specifies a particular traversal (index 1 to 1 million in ascending order), but for an implementation of "sum" I only need "for each element" (no particular order) semantics. I don't want to even think about whether by using such an (overly specific) loop, I'm making the code difficult or impossible to parallelize (in the presence of some side effects, for example in C, it will likely be).
- moomin 13y agoActually, no, for sum you need three things: how to start (0), how to accumulate (plus) and how to combine two reductions (plus again). This is exactly what fold doe Equally, for filter, it's empty list, conj or not and concat. (Just to demonstrate that sometimes the combine is different from the accumulate stage.)
- derefr 13y ago> Actually, I think what you're really asking for is the ability to write sequential code and have the compiler work out if it could be parallel. Nah; the ability to write parallel code and have the compiler work out how to make it sequential-when-necessary would be better. Like JITing an agent-based system into bits of single-threaded procedural code.