-
Notifications
You must be signed in to change notification settings - Fork 5
Fix Newtype instance in test code #14
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
Conversation
CI fails because fun deps don't propagate:
|
I think you just need to add that constraint to the constraints for the instance. I don’t foresee any issues with that ... Actually, did we drop the restriction on rows? Might be able to remove the type equality constraint and just replace inner with the record, if we did. |
Can you clarify? Also, is this test still the best way to test this library? |
@JordanMartinez I PRd your branch with my idea but I think we probably need to test more (especially since we got rid of the methods): https://github.com/JordanMartinez/purescript-type-equality/pull/1 |
I've merged your changes. Just a thought, but since we need the class TypeEquals :: forall k. k -> k -> Constraint
class Coercible a b <= TypeEquals a b | a -> b, b -> a where
proof :: forall p. p a -> p b
instance refl :: TypeEquals a a where
proof a = a
to :: forall a b. TypeEquals a b => a -> b
to = coerce
from :: forall a b. TypeEquals a b => b -> a
from = coerce Regardless, I feel like we need more tests to verify this code works properly. |
Using |
I don't think we need more tests - this is a case where we should be trusting the compiler, I think. |
Ok. I've pushed the changes. |
Looks good to me! I’d like to hear from @kl0tl before merging though. |
Incidentally I think using coerce feels wrong to me because it would allow you to write those functions in such a way that wouldn’t ensure that |
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.
Nominally equal types are also representationally equal, so since TypeEquals
embodies nominal equality this makes sense to me!
I don’t think implementing to
and from
with coerce
would be wrong per se because the TypeEquals a b
constraint doesn’t hold unless the types are really the same, but it might be worthwhile for those functions to serve as an example of how to actually use the type equality proof?
test/Main.purs
Outdated
(TypeEquals inner { message :: String } | ||
) => Newtype RecordNewtype inner |
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.
There’s no need for those parens now that the Coercible constraint is introduced by TypeEquals itself.
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.
Done.
Yeah exactly, I think we should be using the type equality proof here for dogfooding reasons as well. |
Pretty sure this is ready to merge. |
Description of the change
Fixes the Newtype instance in the test code that currently prevents CI from passing.
Checklist: