Suppose I have 10 heavy different functions (parallel or not) deciding about the same problem.
Is there a good way to implement a voting scheme that lazy-automatically realizes when a majority is reached and no more calculation is needed?
obs.: This is more a question about scope/limits of lazy ev.
Of course a simple “if” could detect a majority.
Thanks
[EDIT 1]
… simple “if” could detect a majority.
Sorry, I meant by “single if” -> “single wait for all process to finish”.
… parallel or not …
I just don’t know parallelism matters in this case. (problems with my ambiguous English)
You can do this without parallel evaluation trivially, using lazy naturals. In this case I chose to use the peano-inf package on hackage: http://hackage.haskell.org/package/peano-inf
Note that 5 is not printed in the trace, because evaluation is cut short before then.
To do this with parallelism requires manually spawning and killing threads, etc, which is fine but certainly less pleasant.
Note that the above code uses standard sum. This sort of uncommon use-case is why, though many feel it isn’t worth it, sum is not made as strict as possible.