-
Notifications
You must be signed in to change notification settings - Fork 5
Use leibniz equality #9
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ module Type.Equality | |
( class TypeEquals | ||
, to | ||
, from | ||
, leibniz | ||
, leibnizOp | ||
) where | ||
|
||
-- | This type class asserts that types `a` and `b` | ||
|
@@ -14,10 +16,26 @@ module Type.Equality | |
-- | Note: any instance will necessarily overlap with | ||
-- | `refl` below, so instances of this class should | ||
-- | not be defined in libraries. | ||
class TypeEquals :: forall k. k -> k -> Constraint | ||
class TypeEquals a b | a -> b, b -> a where | ||
to :: a -> b | ||
from :: b -> a | ||
leibniz :: forall p. p a -> p b | ||
|
||
instance refl :: TypeEquals a a where | ||
to a = a | ||
from a = a | ||
leibniz a = a | ||
|
||
newtype Op :: forall k. k -> k -> Type | ||
newtype Op a b = Op (forall p. p b -> p a) | ||
|
||
leibnizOp :: forall p a b. TypeEquals a b => p b -> p a | ||
leibnizOp = case leibniz (Op (\pa -> pa) :: Op a a) of | ||
(Op f :: Op a b) -> f | ||
|
||
newtype To a = To a | ||
|
||
to :: forall a b. TypeEquals a b => a -> b | ||
to a = case leibniz (To a) of | ||
To b -> b | ||
Comment on lines
+36
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point, I missed that that was possible. |
||
|
||
from :: forall a b. TypeEquals a b => b -> a | ||
from b = case leibnizOp (To b) of | ||
To a -> a | ||
Comment on lines
+40
to
+41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is If we don’t want any dependency There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think having the symmetric/opposite form of Leibniz in this place is good, because sometimes you’ll need both directions (just for easier access) and you don’t want to have to add another constraint. It’s just one newtype that only needs to be used internally. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I would prefer not to export leibnizOp at first; if people want to flip it around they can use the leibniz library, right? If we’re saying this is only the basic stuff and people should use the leibniz library for more involved usage, then to me that seems consistent with not exporting leibnizOp. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about
proof
ortypeEquals
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like
proof
for this, yeah