Haskell: Why did โ€œsteamโ€ determine how it was?

par declared as:

par  :: a -> b -> b

Note that this argument is discarded. To use steam, you need to play tricks, for example, using the same expression several times.

If its purpose is to execute a and b in parallel, why it has not been defined like this:

par  :: (a, b) -> (a, b)

Taking a tuple of (unvalued) expressions and returning the same expressions - while they potentially materialize in the background threads.

It seems the last model is simpler than the first. Why was the design chosen in this way?

+5
source share
2 answers

In the first, you can easily fix more than two calculations,

c1 `par` c2 `par` c3 `par` c4 `pseq` something c1 c2 c3 c4

which would be rather cumbersome in the latter.

+8
source

parTuple2 Control.Parallel.Strategies, :

evalTuple2 :: Strategy a -> Strategy b -> Strategy (a, b)

, par , par " ", 24 Real World Haskell, quicksort:

,    .

  • .
  • .
  • .
  • .
  • , .

Parallelism, , :

, . , , ; - , . , ,

+7

All Articles