3 ms·
left-fold and right-fold are not the only two. If you're dealing with commutative and associative operators, you can group them up in a binary (or n-ary) hierar
by aufreak3 16y ago
left-fold and right-fold are not the only two. If you're dealing with commutative and associative operators, you can group them up in a binary (or n-ary) hierarchy for parallel execution as well ... and is there a name for that?
map is obviously parallelized in a purely functional language. My opinion is that fold, otoh, is better limited to use with commutative and associative operators for clarity and transparent parallelization. That way, you don't have to think about whether you need to use a left or a right fold, or indeed a parellel fold.
Other "iterations" can be expressed using explicit recursion using an accumulator ... again, for clarity.
- cabalamat 16y ago> left-fold and right-fold are not the only two. If you're dealing with commutative and associative operators, you can group them up in a binary (or n-ary) hierarchy for parallel execution as well Unify isn't a functional language, nor do I particularly care about execution speed at present -- I'm writing it to test a concept I call Viewability. Having said that, the next version of Unify may well be more functional than the current one, and if so it could havre a way of tagging operators as commutative or associative, so the compiler can produce efficient code. > map is obviously parallelized in a purely functional language It's obviously parallelisable. It can only actually be parallelised if you have more than one CPU. > My opinion is that fold, otoh, is better limited to use with commutative and associative operators for clarity and transparent parallelization. I think it makes more sense in those cases, yes. In fact you could make fold a method with multiple implementations depending on the type of function, e.g: /* version that works with any function */ (fold ((Function f) ar) ...) /* version that requires a function that is associative and commutative, and can do appropriate optimisations */ (fold ((AssComFunction f) ar) ...)
- dkersten 16y agoand is there a name for that? In Clojure its preduce, I believe (for parallel reduce; in Intel Threading Building Blocks its called parallel_reduce).
- silentbicycle 16y agoIn k, a similar operation is called "peach", for "parallel each", though (as with J and APL) most of the operations already have an implicit map/loop built-in.