4 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) hier
by 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) ...)