purescript / purescript-typelevel-prelude

Types and kinds for basic type-level programming
BSD 3-Clause "New" or "Revised" License
63 stars 21 forks source link

Add Equals to Type.Data.Boolean? #65

Open kl0tl opened 3 years ago

kl0tl commented 3 years ago

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
JordanMartinez commented 3 years ago

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?

kl0tl commented 3 years ago

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

JordanMartinez commented 3 years ago

Ah, good point.

JordanMartinez commented 2 years ago

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