-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor CanHold(Un)Signed Typeclass Instances (#23)
- 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 here 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.
- Loading branch information
Showing
1 changed file
with
78 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters