ekmett / ersatz

A monad for interfacing with external SAT solvers
Other
63 stars 15 forks source link

Generalize type of (===) ? #31

Closed jwaldmann closed 2 years ago

jwaldmann commented 7 years ago

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).

jwaldmann commented 7 years ago

"instance Equatable Bool" - no, this does not help.

andersk commented 6 years ago
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
glguy commented 2 years ago

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.