O'Reilly logo

Haskell Cookbook by Yogesh Sajanikar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

monad-par defines the Par monad which defines the following primitives:

  • new: Define a new empty IVar
  • get: Wait for having some value in IVar
  • put: Put some value into IVar
  • fork: Signal that the input Par action can be run in parallel
  • spawn: A function to run an action in parallel to produce an IVar

Internally, monad-par implements a way to balance these activities across threads by scheduling and balancing them. monad-par allows us to specify parallel tasks without getting into the nitty-gritty of actually scheduling tasks.

Also note that, in this recipe, we have used a threshold to run the task sequentially. This is to increase the granularity of the tasks. This speeds up more speedup when there is no threshold. As because ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required