Closed jachymb closed 8 years ago
There is universeDef
in universe-base
, which let you define:
instance Universe Foo where universe = universeDef
instance Finite Foo
-- or even on recent enough GHC (with DefaultSignatures)
instance Universe Foo
instance Finite Foo
We could add BoundedEnum
though:
newtype BoundedEnum a = BoundedEnum { getBoundedEnum :: a }
instance (Bounded a, Enum a) => Universe (BoundedEnum a) where universe = universeDef
instance (Bounded a, Enum a) => Finite (BoundedEnum a)
what @dmwit thinks about that?
Right, universeDef
(or using the default, for GHCs that support it) is the intended way to use [minBound .. maxBound]
. Additionally with DeriveAnyClass
turned on you ought to be able to write, for example:
data Suit = Clubs | Diamonds | Spades | Hearts deriving (Bounded, Enum, Universe, Finite)
I'd be perfectly happy with adding a newtype if @jachymb plans to use it, but probably the above mechanisms are already convenient enough...?
It seems enough, I did not know it. Thank you
Could we have instance for Enum a, Bounded a where universe = [minBound..maxBound]?