Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8339351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:51:45+00:00 2026-06-09T04:51:45+00:00

Haskell provides a par combinator, which queues a spark for possible evaluation in parallel

  • 0

Haskell provides a par combinator, which queues a “spark” for possible evaluation in parallel with the current thread. It also provides a pseq combinator, which forces evaluation of pure code to occur in a specific order.

What Haskell does not appear to provide is a way to generate several sparks and then wait for them all to finish. This is quite trivial to achieve with explicit concurrency, but appears to be impossible with pure sparks.

In part, this is perhaps because of the intended use-case for sparks. They appear to be designed for speculative evaluation. That is, doing work which might be needed, but might not be. Hence, sparks only run on cores which are otherwise idle.

However, this is not my use-case. I have a bunch of results which I know, for a fact, will be needed soon. And if I start trying to process the results before the sparks have fired, I’ll just end up single-threaded again with a bunch of fizzled sparks.

Of course, of par waited for sparks to complete, it wouldn’t achieve any parallelism! But it would be really useful if there were some way to produce several sparks and then wait for them all to finish. I can’t find any way to do that though.

Does anybody have any useful suggestions? (Other than “use explicit concurrency”, obviously.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T04:51:46+00:00Added an answer on June 9, 2026 at 4:51 am

    The Really Short Answer

    You can’t.

    The Short Answer

    To wait for a spark to finish, try to evaluate what the spark was evaluating. For example, if you have expressions a and b, to calculate a + b, you can do

    a `par` b `par` (a + b)
    

    or

    a `par` b `pseq` (a + b)
    

    The Long Answer

    When you create a spark by using par, you are telling the run time system “I will need this value later, so you should evaluate it in parallel.” When you later need the value, either the spark has evaluated the expression or it hasn’t. If it has, the thunk will be replaced by a value, and so re-evaluation has no cost – it is just fetching the value. If it hasn’t been evaluated be the spark then waiting for the spark is useless – it might take a while to get scheduled, and the thread waiting is wasting time. Instead of waiting, you should just evaluate the expression yourself. Essentially, there is no need to wait for a spark. You just try to evaluate the original expression and get performance benifits.

    Also, a note on speculation – although sparks can be and often are used for speculation, that is not completely what they are designed for. I see par being used for simple parallelization, as in pfib below, much more often than I see it used for speculation.

    Examples

    A standard example is parallelizing the Fibonacci numbers, from the serial

    fib 0 = 0
    fib 1 = 1
    fib n = fib (n - 1) + fib (n - 2)
    

    to the parallel

    pfib 0 = 0
    pfib 1 = 1
    pfib n = l `par` r `pseq` (l + r) where
        l = pfib (n - 1)
        r = pfib (n - 2)
    

    .

    Now for an example using speculation:

    spec :: a -- a guess to the input value
        -> (a -> b) -- a function to tranform the input value
        -> a -- the actual input value - this will require computation
        -> b -- the function applied to the input value
    spec guess f input = let speculation = f guess in speculation `par`
        if guess == input
            then speculation
            else f input
    

    The hackage package I got this from, speculation, actually had a couple optimizations like not doing this on a single core and checking whether the input was already evaluated, but that doesn’t matter to the working of the function.

    Other Solutions that Make Things More Explicit

    • monad-par
    • Strategies, which make use of par.
    • Messing with IO. There are a lot of things here.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The documentation of Data.Array reads: Haskell provides indexable arrays, which may be thought of
Haskell provides the feature something like f = f1 . f2 How can I
I just recently started diving into Real World Haskell and the book provides some
In Haskell, there is a function take n list which returns the first n
Reading Real World Haskell, on page 95 the author provides an example: myFoldl f
Is it possible to create PHP extensions with Haskell? Usually PHP extensions are written
The stringsearch package provides fast find/replace functionality for Haskell ByteStrings. Does there exist corresponding
Does anyone know if it is possible to do lock-free programming in Haskell? I'm
Following a haskell tutorial , the author provides the following implementation of the withFile
I want to write a function in haskell which would not mind in what

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.