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

Inject/Project find effects nested on the left #219

Merged
merged 14 commits into from
Sep 29, 2019
Merged

Conversation

robrix
Copy link
Contributor

@robrix robrix commented Sep 23, 2019

This PR allows effects to occur on the left as well as the right, which will enable us to split Error up into both Throw and Catch, reintroduce NonDet as a synonym for Empty :+: Choose, etc.

  • Reintroduces NonDet as a synonym for Empty :+: Choose.
  • Uses NonDet in the Carrier instances for NonDetC, CutC, and CullC.
  • Splits Error into Throw & Catch. Deferring to a future PR.
  • Redefines Fail as a synonym for Throw String. Deferring to a future PR.
  • Fixes Member constraints only allow nesting on the right #213.

@robrix robrix changed the base branch from simpler-constraints to master September 25, 2019 15:29
@robrix robrix marked this pull request as ready for review September 26, 2019 01:24
eff (R (R (R other))) = CullC (eff (R (R (R (handleCoercible other)))))
eff (R (L (L Empty))) = empty
eff (R (L (R (Choose k)))) = k True <|> k False
eff (R (R other)) = CullC (eff (R (R (handleCoercible other))))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Basically just reassociating here.

inj = reassoc . inj where
reassoc (L l) = L (L l)
reassoc (R (L l)) = L (R l)
reassoc (R (R r)) = R r
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reassociation here won’t be too bad a performance hit as long as we’re reasonable about using left-nested sums.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you elaborate on what you mean by this?

Copy link
Collaborator

Choose a reason for hiding this comment

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

And can we document why we need to reassociate here (and maybe drop a link to DTALC for people who are wondering about why all these OVERLAPPABLE pragmas need to happen?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you elaborate on what you mean by this?

Basically, this assumes that trees will generally be right-leaning. So anything exclusively right-chained won’t ever see this instance, and if you have (A :+: B) :+: C that’s an extremely minor hit (as your benchmark demonstrates). But a long left-chain—which is extremely unlikely to happen, and never by accident; you would have to work quite hard to design your effects thus—will take more of a hit because it has to do a bunch more reassociation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And can we document why we need to reassociate here (and maybe drop a link to DTALC for people who are wondering about why all these OVERLAPPABLE pragmas need to happen?

I’m gonna do this in #223 to avoid conflicts.

Copy link
Collaborator

@patrickt patrickt left a comment

Choose a reason for hiding this comment

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

Some documentation quibbles, and I confess that I’m not looking forward to changing these reassociations in semantic, but this is the right thing, I think.

ChangeLog.md Show resolved Hide resolved
src/Control/Effect/NonDet.hs Show resolved Hide resolved
inj = reassoc . inj where
reassoc (L l) = L (L l)
reassoc (R (L l)) = L (R l)
reassoc (R (R r)) = R r
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you elaborate on what you mean by this?

inj = reassoc . inj where
reassoc (L l) = L (L l)
reassoc (R (L l)) = L (R l)
reassoc (R (R r)) = R r
Copy link
Collaborator

Choose a reason for hiding this comment

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

And can we document why we need to reassociate here (and maybe drop a link to DTALC for people who are wondering about why all these OVERLAPPABLE pragmas need to happen?

@robrix
Copy link
Contributor Author

robrix commented Sep 29, 2019

Some documentation quibbles, and I confess that I’m not looking forward to changing these reassociations in semantic, but this is the right thing, I think.

I can’t think of anything in semantic that would need to be changed as a result of this.

@robrix robrix merged commit a22fbc0 into master Sep 29, 2019
@robrix robrix deleted the to-the-left-to-the-left branch September 29, 2019 16:10
@robrix robrix mentioned this pull request Oct 9, 2019
3 tasks
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.

Member constraints only allow nesting on the right
2 participants