Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add type-level Equals for Boolean #66

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/Type/Data/Boolean.purs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ module Type.Data.Boolean
, class IsBoolean
, reflectBoolean
, reifyBoolean
, class Equals
, equals
, class And
, and
, class Or
Expand Down Expand Up @@ -35,6 +37,17 @@ reifyBoolean :: forall r. Boolean -> (forall proxy o. IsBoolean o => proxy o ->
reifyBoolean true f = f (Proxy :: Proxy True)
reifyBoolean false f = f (Proxy :: Proxy False)

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

instance equalsTrueTrueTrue :: Equals True True True
else instance equalsTrueFalseFalse :: Equals True False False
else instance equalsFalseTrueFalse :: Equals False True False
else instance equalsFalseFalseTrue :: Equals False False True

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

-- | And two `Boolean` types together
class And :: Boolean -> Boolean -> Boolean -> Constraint
class And lhs rhs out | lhs rhs -> out
Expand Down