purescript-typelevel-prelude icon indicating copy to clipboard operation
purescript-typelevel-prelude copied to clipboard

Add Equals to Type.Data.Boolean?

Open kl0tl opened this issue 5 years ago • 4 comments

We have Type.Data.Ordering.Equals and Type.Data.Symbol.Equals but no Type.Data.Boolean.Equals.

Is there any reason for not wanting or needing this class?

I assume it would be implemented like this:

class Equals :: Boolean -> Boolean -> Boolean -> Constraint
class Equals lhs rhs out | lhs rhs -> out, lhs out -> rhs, rhs out -> lhs

instance equalsTrueTrue :: Equals True True True
else instance equalsTrueFalse :: Equals True False False
else instance equalsFalseTrue :: Equals False True False
else instance equalsFalseFalse :: Equals False False True

equals :: forall proxy l r o. Equals l r o => proxy l -> proxy r -> Proxy o
equals _ _ = Proxy

kl0tl avatar Nov 23 '20 21:11 kl0tl

Yes, we should add it for completeness.

However, now that we have polykinds, is it possible for Equals to become polymorphic, so that we don't need an Ordering.Equals or Symbol.Equals?

JordanMartinez avatar Nov 26 '20 19:11 JordanMartinez

I don’t think we can have a single polymorphic Equals class: its instance for symbols would overlap the other instances for orderings and booleans!

Also since Boolean has only two inhabitants we can have more functional dependencies (lhs out -> rhs and rhs out -> lhs), allowing the compiler to deduce one of the parameters from the other and the result (which isn’t possible for symbols nor orderings when the result is False).

kl0tl avatar Nov 26 '20 19:11 kl0tl

Ah, good point.

JordanMartinez avatar Nov 26 '20 19:11 JordanMartinez

#66 wasn't merged because a concrete use case wasn't known at that particular time.

JordanMartinez avatar Dec 01 '21 04:12 JordanMartinez