Add SmallBounded* type classes and related instances; Fixes #38#39
Add SmallBounded* type classes and related instances; Fixes #38#39bbarker wants to merge 4 commits intopurescript:masterfrom
Conversation
|
I think perhaps this would be better off as a separate library rather than including it here. I totally get the motivation for it, but I think it's a bit dodgy - even following the laws set out here, if there's a Even aside from deep nestings of |
|
Thanks for the discussion @garyb, a few comments and questions:
Yes, exactly, though rate, it pops up, that's why I suggest
This is a very good point; I had thought of this, and though it seems rare, I guess it could come up. Again with using I'm wondering if there's any way to do a compile-time check on Cardinality, but probably not (outside of unit tests, which could be advised). Still could be really cool to have that ability.
|
|
Regarding the compile-time check, this might be possible by using something like, https://github.com/danieljharvey/purescript-refined, though adding that dependency would likely be another point in the direction of doing this as a separate library. For instance (half pseudo code): - | A lawful subclass of `Bounded` to denote
-- | Cardinality a << Cardinality Int
class Bounded a <= SmallBounded a
-- | A lawful subclass of `BoundedEnum` to denote
-- | Cardinality a << Cardinality Int
class BoundedEnum a <= SmallBoundedEnum a where
sizeCheck :: LessThan (Size Int)
instance smallBoundedEnum :: (SmallBounded a, BoundedEnum a)
=> SmallBoundedEnum a where
sizeCheck = refine $ unwrap cardinality |
I don't have an opinion on whether this should be a separate library, but I don't see how what you said is a problem. |
|
Ah yeah, you're right. My thing would only be true if there was an instance like |
For addressing #38; I've tested this on a personal project and it works as desired there with
boundedEnumMaybe.