haskell / haskell/parallel

minimal but convincing example?

Open
#50 3 comments 4 reactions 0 assignees View on GitHub
Dominant language
Haskell
Stars
98
Forks
24
PR merge metrics
No merged PRs in 30d

Description

I would very much want that the documentation contains a minimal convincing example
(and that this would also be included in tests, so we can be sure that it works).

"Convincing" in the sense that
* running with `+RTS -N` (for small k) visibly, and progressively, reduces execution time
* code is readable and stand-alone (no fancy extra libraries)

For reference, I am using the following C# example (sum of bitcounts) in teaching
and I like that it has these properties:

* it's two one-liners (naive bitcount implementation, naive summation)
* parallelisation is trivial (add `.AsParallel()`)
* effect is visible (cut execution time nearly in half)
* works out-of-the-box in `csharp` REPL

```
Func bc = (int x) => { int c=0; while (x>0) { c += x%2 ; x >>= 1 ; } return c; }

Time(() => Console.WriteLine( Enumerable.Range(0,1<<27).Select(bc).Sum()))
1811939328
00:00:03.5504990

Time(() => Console.WriteLine( Enumerable.Range(0,1<<27).AsParallel().Select(bc).Sum()))
1811939328
00:00:02.1616790
```
If there is such an example (my naive use of `parListChunk` does not seem to cut it) I'm happy to write it up as haddock and submit a PR.

NB - Sure I know (and discuss with students) that there are better implementations of `bc`, and that sum-of-bitcounts (up to powers of two) has a closed form, so we don't actually _need_ any of this...

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by locating the Haddock documentation and existing examples around parListChunk. Run a minimal standalone example with +RTS -N and determine how it can be exercised in tests; done means the example is readable, uses no extra libraries, shows progressively shorter execution times, and is covered by a working test.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
documentation, testing
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.