Skip to content

Commit 6f96c9d

Browse files
committed
Improve documentation of Control.Parallel
1 parent 4fb0cc2 commit 6f96c9d

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

Control/Parallel.hs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module Control.Parallel (
2727
) where
2828

2929
#ifdef __GLASGOW_HASKELL__
30-
import qualified GHC.Conc ( par, pseq )
30+
import qualified GHC.Conc (par, pseq)
3131

3232
infixr 0 `par`, `pseq`
3333
#endif
@@ -38,7 +38,8 @@ infixr 0 `par`, `pseq`
3838
-- argument in parallel with the second. Returns the value of the
3939
-- second argument.
4040
--
41-
-- @a ``par`` b@ is exactly equivalent semantically to @b@.
41+
-- The result of @a ``par`` b@ is always @b@, regardless of wether
42+
-- @a@ evaluates to a bottom, so for example @par undefined x = x@.
4243
--
4344
-- @par@ is generally used when the value of @a@ is likely to be
4445
-- required later, but not immediately. Also it is a good idea to
@@ -47,9 +48,8 @@ infixr 0 `par`, `pseq`
4748
-- running it in parallel.
4849
--
4950
-- Note that actual parallelism is only supported by certain
50-
-- implementations (GHC with the @-threaded@ option, and GPH, for
51-
-- now). On other implementations, @par a b = b@.
52-
--
51+
-- implementations (GHC with the @-threaded@ option, for now).
52+
-- On other implementations, @par a b = b@.
5353
par :: a -> b -> b
5454
#ifdef __GLASGOW_HASKELL__
5555
par = GHC.Conc.par
@@ -58,8 +58,13 @@ par = GHC.Conc.par
5858
par a b = b
5959
#endif
6060

61-
-- | Semantically identical to 'seq', but with a subtle operational
62-
-- difference: 'seq' is strict in both its arguments, so the compiler
61+
-- | Like 'seq' but ensures that the first argument is evaluated before returning.
62+
--
63+
-- @a ``pseq`` b@ evaluates @a@ to weak head normal form (WHNF)
64+
-- before returning @b@.
65+
--
66+
-- This is similar to 'seq', but with a subtle difference:
67+
-- 'seq' is strict in both its arguments, so the compiler
6368
-- may, for example, rearrange @a ``seq`` b@ into @b ``seq`` a ``seq`` b@.
6469
-- This is normally no problem when using 'seq' to express strictness,
6570
-- but it can be a problem when annotating code for parallelism,
@@ -71,7 +76,6 @@ par a b = b
7176
-- strict in its first argument (as far as the compiler is concerned),
7277
-- which restricts the transformations that the compiler can do, and
7378
-- ensures that the user can retain control of the evaluation order.
74-
--
7579
pseq :: a -> b -> b
7680
#ifdef __GLASGOW_HASKELL__
7781
pseq = GHC.Conc.pseq

0 commit comments

Comments
 (0)