Count the frequency of letters in texts using parallel computation.
Parallelism is about doing things in parallel that can also be done sequentially. A common example is counting the frequency of letters. Employ parallelism to calculate the total frequency of each letter in a list of texts.
Count letters, ignoring case and nonletters, and return a dictionary from lowercase letters to their counts. Treat letters as Unicode scalar values; Unicode normalization is not required.
Use pf.Parallel.map!(items, { workers, task }) from the roc-parallel platform to process the given items using a pure task function, in parallel across multiple threads (given by workers).
The results are returned in the input order once all items have been processed.
You only need to edit ParallelLetterFrequency.roc.
Unlike most other exercises, this exercise uses effectful functions.
Run the tests with roc --opt=speed parallel-letter-frequency-test.roc, rather than roc test.
Any error returned by the Roc code is reported by the platform, using a different format than usual.
You may also want to check out the bank-account exercise, which explores a different side of concurrency: applying updates safely to shared state.
Sign up to Exercism to learn and master Roc with 139 exercises, and real human mentoring, all for free.
We explore the differences between concurrency and parallelism, looking at different approaches taken by languages such as JavaScript, Go, Elixir and Rust.