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

Is ParAff Actually Alternative? #183

Open
eric-corumdigital opened this issue Nov 5, 2019 · 7 comments
Open

Is ParAff Actually Alternative? #183

eric-corumdigital opened this issue Nov 5, 2019 · 7 comments

Comments

@eric-corumdigital
Copy link
Contributor

Distributivity: (f <|> g) <*> x = (f <*> x) <|> (g <*> x)

Let r ∷ Ref Int, f = delay 1.0, g = delay 2.0, x = modify (_ + 1) r

Then

  (delay 1.0 <|> delay 2.0) <*> modify (_ + 1) r
= (delay 1.0 <*> modify (_ + 1) r) <|> (delay 2.0 <*> modify (_ + 1) r)

But, by duplicating the Ref.modify (_ + 1) r effect and running both in parallel, r is incremented by 2 rather than 1.

(Yes, I fudged some types here for brevity).

@natefaubion
Copy link
Collaborator

I guess that depends on what = we are referring to 😄.

@natefaubion
Copy link
Collaborator

natefaubion commented Nov 5, 2019

More seriously, <|> is a race, and losers are cancelled, so I think this particular example is bad since it won't be run twice.

@eric-corumdigital
Copy link
Contributor Author

@natefaubion I am using the ParAff instance for both <|> and <*>, so it should run twice.

@natefaubion
Copy link
Collaborator

Again, I think this kind of comes down to what you mean be =. If it's observationally equal after interpretation, than distributivity can never be satisfied by anything effectful or referential. That sounds very strict and greatly limits what is Alternative. Maybe there needs to be a middle ground in the hierarchy?

@eric-corumdigital
Copy link
Contributor Author

eric-corumdigital commented Nov 14, 2019

The main interest of Aff is effects. I am just looking at how usual effects work, like printing to the console, and making appropriate generalisations.

Strict or not, that just seems to be the way things are.

@artemisSystem
Copy link

wouldn't (g <*> x) be cancelled before it could run its modify, though?

@safareli
Copy link
Contributor

safareli commented Apr 2, 2020

no as the <*> is of ParAff which executes both g and x in parallel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants