Divisible decidable alt apply instances #2014
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds several new instances that serve the techniques laid out in the derivation chapter of FP for Mortals.
A few notes on this.
These are "orphaned" instances in the sense that you need to import them to use them. They are all defined in terms of other typeclasses. Putting them in the companion objects of their own typeclasses seems wrong because it creates ambiguity, but they target polymorphic types so there's no other companion object to house them. I couldn't determine whether there's precedent for this sort of thing in the project as of now.
There's a TODO on some hand-wavy garbage Equal instance I threw in a test for functions that return Int. I figured I'd see if this was super offensive to anyone before deep diving into the laws to see if I could target a type with less inhabitants. If anyone is offended and doesn't mind guiding me in a direction to do better, I'd appreciate the help.
It seems unfortunate to me to have Decidable extend Divisible. Here are the instances I ported - https://gist.github.com/beezee/533285b2123fb7cf6fd77456f061853e which target slightly different definitions of Decidable and Divide. The constraints for those implementation are much less, and they serve the purpose of typeclass derivation faithfully with the weaker definitions.
Awaiting feedback if people find value in this.