Skip to content

Fix dot documentation - #32

Closed
treeowl wants to merge 2 commits into
haskell:masterfrom
treeowl:fix-dot-doc
Closed

treeowl wants to merge 2 commits into
haskell:masterfrom
treeowl:fix-dot-doc

Conversation

@treeowl

@treeowl treeowl commented Jun 4, 2018 •

Copy link
Copy Markdown
Contributor

I goofed up and made the strat1 `dot` strat1 = strat1 law too
strong. Fix that. Also, add laws for strat `dot` rseq and
strat `dot` rpar.

I goofed up and made the ``strat1 `dot` strat1 = strat1`` law too
strong. Fix that. Also, add laws for ``rpar `dot` rseq`` and
``rseq `dot` rpar``.
--
-- > strat `dot` r0 == strat
-- > strat `dot` rseq == strat
-- > strat `dot` rpar == strat

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that true?

@treeowl treeowl Jun 5, 2018 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe so, yes. runEval m is a lifted value; it doesn't do anything until it's forced. Forcing runEval (r0 x) runs the usual return x IO computation, so that gives you x. Forcing runEval (rseq x) runs an IO computation that forces x to WHNF and returns the result (exactly the same as forcing x directly). Forcing runEval (rpar x) runs an IO computation that sparks a thread to evaluate x to WHNF, but immediately forces the result so the thread (almost certainly) fizzles.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r0 `dot` rseq == r0
r0 `dot` rpar == r0

Would be counterintuitive to my expectations, of the first description of dot, namely: "Compose two strategies sequentially". Or more explicitely:

"Composing the 'do nothing'-strategy with the 'evaluate to WHNF'-strategy sequentially, creates the 'do nothing'-strategy"

Am I the only, who thinks this sounds weird?

@treeowl treeowl Jun 9, 2018 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r0 `dot` rseq is not r0. But rseq `dot` r0 = rseq.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last comment corrected.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dot is a composition operator in a semigroupoids sense: namely, it is associative. But it doesn't form a category, which makes intuition around it a little tricky. @Borgvall, by definition,

f `dot` g = \x -> f (runEval (g x))

Think about what runEval (r0 x), runEval (rpar x), and runEval (rseq x) do when forced. Ultimately the same thing (if you ignore sparks that fizzle). If you don't force them, they all do ... nothing.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I care about sparking, this is the main reason to use this library!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still concerned about strat dot rpar == strat

We can construct contrived examples in which this doesn't apply, at least operationally (and operationally is after all the point of the library, so the equalities should be operational ones). e.g.

let strat n x = rseq (fib n) >> return x  in strat 99999 `dot` rpar

If strat is very slow then the spark doesn't fizzle immediately and we get some useful parallelism. Of course it's hard to reliably define a strategy that's very slow (the example above could easily be optimised), but the fact that it's possible at all implies that we can't assume the spark fizzles immediately.

Comment thread Control/Parallel/Strategies.hs Outdated
@Borgvall

Borgvall commented Jun 9, 2018 via email

Copy link
Copy Markdown
Contributor

@treeowl

treeowl commented Jun 9, 2018 via email

Copy link
Copy Markdown
Contributor Author

@Borgvall

Copy link
Copy Markdown
Contributor

In the edited version of your comment you sai: "r0 dot rseq is not r0", but in line 308 you say:

-- strat `dot` rseq == strat [for all strat even r0]

So you are still contradicting yourself.

@treeowl

treeowl commented Jun 10, 2018

Copy link
Copy Markdown
Contributor Author

Yes, I did make a mistake. r0 `dot` rseq is indeed r0 after all.

@Kleidukos

Copy link
Copy Markdown
Member

@treeowl can I let you merge it?

@treeowl

treeowl commented Jan 19, 2024

Copy link
Copy Markdown
Contributor Author

@treeowl can I let you merge it?

I don't understand the question. I don't have permission to merge things to master.

@Borgvall

Copy link
Copy Markdown
Contributor

As this old merge request has been resurrected, I revisited it. My current point of view is, that the documentation is as weird as the implementation of dot, and the documentation changes of @treeowl simply expose this fact.

IMHO the dotcombinator should be deprecated. The reasonable way to "compose two strategies sequentially" is to use Control.Monad.>=>.

@konsumlamm

Copy link
Copy Markdown
Collaborator

I agree that r0 `dot` rseq == `r0 is counterintuitive. >=>/<=< indeed gives you a more intuitive (IMO) strategy composition, e.g. r0 <=< rseq == rseq.

We should definitely fix the documentation (although there's still an unresolved review), but I'm sympathetic to deprecating dot, unless someone has an argument why this strategy composition makes sense.

@konsumlamm konsumlamm mentioned this pull request Apr 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants