-
Notifications
You must be signed in to change notification settings - Fork 90
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
Remove the ref equality check in the Eq Array instance #187
Remove the ref equality check in the Eq Array instance #187
Conversation
See discussion here: 3b0d306
Have we really determined that "=== implies ==" does not follow from the laws? And if so, could we change that? Isn't @hdgarrood's example (reproduced below) ultimately because let x = [NaN]
x === x; // true |
I think "=== implies ==" does follow from the This example is indeed ultimately due to It is of course unfortunate that |
It is if you have two arrays to compare, but not if something else uses arrays under the hood.
So where do you draw the line for "potentially dangerous"? Presumably you're not saying that nobody should ever rely on any typeclass law. (edit: this is not fair, I know you're not saying that, and I know that we are in the realm of judgment calls where a bright red line might not exist, but still...) What's different here? I guess "it's only about performance" is one answer to this. It does not seem fair to me that a law-abiding optimization is too "potentially dangerous" to be the default, whereas a know to be broken instance is the default. I'm not advocating to get rid of |
Correct, but if something else uses arrays under the hood, then it ought to be the responsibility of that other thing to opt in to these unsafe referential equality checks, surely?
It's that a property of the language — namely, referential transparency — is being violated. It's not just that you'll end up with incorrect behaviour, it's that you get incorrect behaviour which the language advertises itself as being able to prevent. I think this puts us into a different category than just encountering incorrect behaviour which arises from an unlawful instance (and, while wrong, at least doesn't violate a property that the language is advertised as having). |
Actually having thought through it a little more, I don't think it's accurate to say it's just
Of course, the oddity with |
As long as you only use the safe subset of PureScript referential transparency should hold. JavaScript's I object to expecting language properties to hold in the presence of unsafe use. I think code should be allowed to use whatever "unsafe" hacks it wants, as long as the interface to the outside world is preserved. For me this interface includes instance laws and other additional requirements that are not checked by the language (like Ugh, I sound like a C person. Undefined behavior for more optimizations! If the programmer isn't careful they get what they deserve! ;) So yeah, maybe you are right. It's hard to admit though. I do think that good things like purity and typeclass laws should allow us to take shortcuts. |
Ok, yes, you're absolutely right there. |
I was just about to say do what you think is best (not that you need my permission — just saying I'd stop complaining...) when I had this terrible idea: We could use instance chains to select the deep comparison for (Yes, I know, I'll see myself out.) |
Sort of related: https://www.reddit.com/r/haskell/comments/4ivvge/why_no_reference_equality/ Anyway are there any objections to merging this and making a patch-level release? |
- This reverts the change in purescript#187 - Provides a major optimization for array equality checking. - Opting into this functionality within all nested records at the moment seems unrealistic compared to just restoring this here. Reviewed By:
- This reverts the change in purescript#187 - Provides a major optimization for array equality checking. - Opting into this functionality within all nested records at the moment seems unrealistic compared to just restoring this here. Reviewed By: pbrant
See discussion here: 3b0d306