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

Refactor: Clean up CanHold(Un)Signed instances #22

Closed
wants to merge 2 commits into from

Conversation

NathanielB123
Copy link
Contributor

@NathanielB123 NathanielB123 commented Jan 16, 2024

  • Avoided redundant transitive instances by doing type-level natural number comparisons
  • Use custom type errors to explain why the instance is not available
  • The downside is that the constraints are not extensible - i.e. users cannot create their own instances for their own numeric types. I think the only way to solve this while keeping the nice type errors would be to rely on overlapping instances (but there might be a trick that I am unaware of)

Note that GHC now (as of 9.8.1) supports a slightly more principled way of adding custom type errors via Unsatisfiable constraints. The main trouble with trying to use it is BitWidth (which doesn't return Constraint). We could create another constraint family with an appropriate error message, or perhaps have it take a b :: Bits standing for the return value and return equality constraints (b ~ B8/b ~ B16, etc...) in the successful cases, hoping Haskell's constraint solver makes everything work out nicely.

NathanielB123 and others added 2 commits January 16, 2024 18:14
Avoided redundant transitive instances by doing type-level natural
number comparisons
Use custom type errors to explain why the instance is not available
The downside is that the constraints are not extensible - i.e: users
cannot create their own instances for their own numeric types.
I think the only way to solve this while keeping the nice type errors
would be to rely on overlapping instances (but there might be a trick
that I am unaware of)
@NathanielB123
Copy link
Contributor Author

I think messed up the PR, again, sorry lol

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.

1 participant