Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dot documentation #32

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Fix dot documentation #32

wants to merge 2 commits into from

Conversation

treeowl
Copy link
Contributor

@treeowl treeowl commented Jun 4, 2018

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
Member

Choose a reason for hiding this comment

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

Is that true?

Copy link
Contributor Author

@treeowl treeowl Jun 5, 2018

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
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?

Copy link
Contributor Author

@treeowl treeowl Jun 9, 2018

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
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
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
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
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.

Control/Parallel/Strategies.hs Outdated Show resolved Hide resolved
@Borgvall
Copy link
Contributor

Borgvall commented Jun 9, 2018 via email

@treeowl
Copy link
Contributor Author

treeowl commented Jun 9, 2018 via email

@Borgvall
Copy link
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
Copy link
Contributor Author

treeowl commented Jun 10, 2018

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

@Kleidukos
Copy link
Member

@treeowl can I let you merge it?

@treeowl
Copy link
Contributor Author

treeowl commented Jan 19, 2024

@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
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
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.

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