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

Member constraints only allow nesting on the right #213

Closed
robrix opened this issue Sep 21, 2019 · 5 comments · Fixed by #219
Closed

Member constraints only allow nesting on the right #213

robrix opened this issue Sep 21, 2019 · 5 comments · Fixed by #219
Assignees
Labels
bug Something isn't working
Milestone

Comments

@robrix
Copy link
Contributor

robrix commented Sep 21, 2019

:+: can technically form the branches of a tree, but we always use it as a right-nested, Pure- or Lift m-terminated list.

This means that following #199, we can’t usefully reintroduce NonDet as a synonym for Choose :+: Empty, because that sum would be nested on the left; and while that wouldn’t impair anything using the Alternative interface, anything requiring Member Choose sig or Member Empty sig wouldn’t work, since neither Choose nor Empty separately unifies with Choose :+: Empty together.

The root of the problem is that even with overlapping instances, ghc’s non-backtracking constraint solver doesn’t allow us to select different instances for occurrences on the left or the right depending on the solution of the context’s constraints.

@robrix robrix added the bug Something isn't working label Sep 21, 2019
@robrix
Copy link
Contributor Author

robrix commented Sep 21, 2019

The root of the problem is that even with overlapping instances, ghc’s non-backtracking constraint solver doesn’t allow us to select different instances for occurrences on the left or the right depending on the solution of the context’s constraints.

We can, however, use advanced overlap techniques involving having a type family compute the path to a member and define instances against said path.

That would allow us to provide NonDet as a synonym for Choose :+: Empty while still satisfying both Member Choose sig and Member Empty sig constraints.

It remains to be seen what this would do to compile times.

@robrix
Copy link
Contributor Author

robrix commented Sep 21, 2019

This problem is also preventing us from splitting up Error into separate Throw and Catch effects (cf #154, 🎩 @mitchellwrosen), since requiring users to write Member (Catch e) sig, Member (Throw e) sig is a very poor substitute for Member (Error e) sig, on top of the already inconvenient requirement of providing both Member and Carrier constraints (cf #212).

@robrix
Copy link
Contributor Author

robrix commented Sep 21, 2019

This could potentially make it more convenient to write carriers handling multiple effects, since they could all nest on the left, with other effects on the right, making the shape of almost all Carrier instances much more uniform.

Further, @lexi-lambda had an idea for the carrier interface which IIRC would benefit from having this kind of uniformity.

@robrix
Copy link
Contributor Author

robrix commented Sep 21, 2019

I’m experimenting with this in diffused-effects; early results are promising, tho I haven’t thrown it at large effect lists yet: fused-effects/diffused-effects#5

@robrix
Copy link
Contributor Author

robrix commented Sep 23, 2019

Negligible effect on compile times unless combined with a type family solution to #212.

@robrix robrix added this to the 0.6 milestone Sep 23, 2019
@robrix robrix self-assigned this Sep 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant