Par and seq

From HaskellWiki
Revision as of 10:36, 30 September 2008 by Lemming (talk | contribs) (summarize Haskell-Cafe discussion)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The functions par and seq have much in common. They have the same signature and thus the same use patterns. The function par let you start a computation in parallel and seq forces a computation to actually take place (avoiding lazy evaluation).

par :: a -> b -> b
seq :: a -> b -> b

You could also define a function par2 which computes the arguments of a two-argument function f in parallel before feeding them to f.

par2 :: (a -> b -> c) -> (a -> b -> c)
par2 f x y = x `par` y `par` f x y

The function par2 is also universal, because you can define par in terms of par2.

par = par2 (\ _x y -> y)

You can see, that par is the more basic combinator, because it scales to any number of arguments.

See also