Skip to content

Commit 489e8d9

Browse files
authored
Deprecate dot (#75)
* Fix dot documentation * Deprecate `dot`
1 parent 3c65c43 commit 489e8d9

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

Control/Parallel/Strategies.hs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -358,20 +358,24 @@ x `usingIO` strat = runEvalIO (strat x)
358358
withStrategyIO :: Strategy a -> a -> IO a
359359
withStrategyIO = flip usingIO
360360

361-
-- | Compose two strategies sequentially.
362-
-- This is the analogue to function composition on strategies.
361+
-- | Compose two strategies.
363362
--
364-
-- For any strategies @strat1@, @strat2@, and @strat3@,
363+
-- > strat2 `dot` strat1 == strat2 . withStrategy strat1
364+
--
365+
-- 'dot' is associative:
365366
--
366367
-- > (strat1 `dot` strat2) `dot` strat3 == strat1 `dot` (strat2 `dot` strat3)
367-
-- > strat1 `dot` strat1 = strat1
368-
-- > strat1 `dot` r0 == strat1
369368
--
370-
-- > strat2 `dot` strat1 == strat2 . withStrategy strat1
369+
-- 'r0' and 'rseq' are one-sided identities of 'dot':
371370
--
371+
-- > strat `dot` r0 == strat
372+
-- > strat `dot` rseq == strat
373+
{-# DEPRECATED dot "'dot' is an unintuitive composition operator. Use 'Control.Monad.<=<` instead." #-}
372374
dot :: Strategy a -> Strategy a -> Strategy a
373375
strat2 `dot` strat1 = strat2 . runEval . strat1
374376

377+
-- Note [dot proofs]
378+
-- ~~~~~~~~~~~~~~~~~
375379
-- Proof of strat2 `dot` strat1 == strat2 . withStrategy strat1
376380
--
377381
-- strat2 . withStrategy strat1
@@ -380,17 +384,14 @@ strat2 `dot` strat1 = strat2 . runEval . strat1
380384
-- == \x -> strat2 (runEval (strat1 x))
381385
-- == \x -> (strat2 . runEval . strat1) x
382386
-- == strat2 `dot` strat1
383-
384-
-- One might be tempted to think that 'dot' is equivalent to '(<=<)',
385-
-- the right-to-left Kleisli composition in the Eval monad, because
386-
-- '(<=<)' can take the type @Strategy a -> Strategy a -> Strategy a@
387-
-- and intuitively does what 'dot' does: First apply the strategy to the
388-
-- right then the one to the left. However, there is a subtle difference
389-
-- in strictness, witnessed by the following example:
390387
--
391-
-- > (r0 `dot` rseq) undefined == Done undefined
392-
-- > (r0 <=< rseq) undefined == undefined
388+
-- Proof of associativity
393389
--
390+
-- (strat1 `dot` strat2) `dot` strat3
391+
-- == (strat1 . runEval . strat2) . runEval . strat3
392+
-- == strat1 . runEval . strat2 . runEval . strat3
393+
-- == strat1 . runEval . (strat2 . runEval . strat3)
394+
-- == strat1 `dot` (strat2 `dot` strat3)
394395

395396
-- | Inject a sequential strategy (i.e., coerce a sequential strategy
396397
-- to a general strategy).

0 commit comments

Comments
 (0)