Generalize type of (===) ?
Closed this issue · 3 comments
Currenty,
class Equatable t where (===) :: t -> t -> Bit
Should this rather be
class Equatable t where (===) :: Boolean b => t -> t -> b
One application is using instance Boolean Bool
for testing. This works as long as I write constraints (and helper functions) with the generic type, but it breaks down as soon as any of them uses ===
.
If the fully general type looks scary, we could write instance Equatable Bool where (===) = (==)
to solve this particular problem (that'd be less intrusive).
"instance Equatable Bool" - no, this does not help.
class Equatable t where (===) :: Boolean b => t -> t -> b
I assume the goal here is to generalize both (===) :: Bits -> Bits -> Bit
and (===) :: Integer -> Integer -> Bool
, but it can’t work as written because it also specializes to the unimplementable (===) :: Bits -> Bits -> Bool
. You would need an associated type:
class Boolean (Equated t) => Equatable t where
type Equated t
(===) :: t -> t -> Equated t
Doing this would require quite a different API for Equatable than we have now. I like the idea of unifying Eq and Equatable but I think we need a concrete, plausible proposal to consider before we can worry about it.