Skip to content

Commit 735dda4

Browse files
committed
Deprecate dot (haskell#75)
* Fix dot documentation * Deprecate `dot`
1 parent 12e1020 commit 735dda4

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
@@ -359,20 +359,24 @@ x `usingIO` strat = runEvalIO (strat x)
359359
withStrategyIO :: Strategy a -> a -> IO a
360360
withStrategyIO = flip usingIO
361361

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

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

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

0 commit comments

Comments
 (0)