-
Notifications
You must be signed in to change notification settings - Fork 3
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 CanHold(Un)Signed Typeclass Instances #23
Refactor CanHold(Un)Signed Typeclass Instances #23
Conversation
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)
TypeError moved from GHC.TypeLits to GHC.TypeError
I have literally no idea why the CI isn't running anymore... Edit: Or where all the random merge commits are coming from... I hate Git |
I tried defining Assert manually, but it seems that the behaviour for when type errors are reported is different for older GHC versions - specifically `SatisfiesBound` was reporting a type error because `BitsNat b <=? BitsNat (BitWidth t)` could not be solved. An easy solution here is to (on older GHC versions) just use `(<=)`. This will lead to lower-quality error messages, but will at least work.
…ielB123/gigaparsec into refactor/num-lexer-bounds
I got signed and unsigned mixed up in the errors emitted by `IsSigned`
Ah, I have to approve all runs for a non-merged contributor Oof, so close. |
On GHC < 9.2.1 term-level `Natural` could not be promoted and `Nat` referred to a distinct kind of type-level naturals. Since then, `Nat` is just an alias for `Natural`, so using `Nat` consistently should work on all versions
Ahh ok that makes sense |
Turning `SatisfiesBound` from a type alias into a type family seemingly prevents the error in the RHS being reported so eagerly (i.e. GHC now properly waits for the arguments to be instantiated)
I love how the PR to reduce the duplication in the instances is +78-41 😂 |
Note that GHC now (as of
9.8.1
) supports a slightly more principled way of adding custom type errors viaUnsatisfiable
constraints. The main trouble with trying to use it here isBitWidth
(which doesn't returnConstraint
). We could create another constraint family with an appropriate error message, or perhaps have it take ab :: 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.