-
Notifications
You must be signed in to change notification settings - Fork 264
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
Universal equality mergeable WIP #393
Conversation
# Conflicts: # parser-typechecker/src/Unison/Runtime/IR.hs
@aryairani and I just discussing, came up with a simple scheme to avoid too much breakage as we evolve the set of builtins. Am going to add to this PR. Have two maps, one of type Note: will need to do the same thing in the mapping from Also discussed having a way to deprecate builtins - make it a |
About the structural equality: does |
@atacratic In that case, |
@atacratic |
@atacratic It would resolve to Universal.== as things stand. |
OK cool. I was confusing myself, thinking that |
(Comparing effect values sounds useful for testing. "Question 1: does this computation return the value I expect? Question 2: did it have the effects along the way that I expect?") |
@aryairani actually, do you want to add the upgrade path stuff to this branch? I don't think I'll get to it for a couple days and I think you have a clearer idea of what to do. I also think it could be better to address with a separate PR, since I feel like we are going to want to start adding version prefixes to the builtin |
@pchiusano My preference is simply to avoid merging the altered references ( We could just:
I'm happy to handle 1. or 2. or both, just lmk. |
I think I was stuck on 1 because some tests started failing as they use == unqualified and now two things match. But I think just update those tests to not use TDNR, and rename the monomorphic versions back to their original names. The other refactoring can be separate PR. |
Makes sense. |
I’ll do 1, we can merge, then you can do 2 at your leisure. 😀 |
Sounds good, I'll do 2. tomorrow. |
Okie dokie, reverted the names to what they were before and updated the tests that were failing, just adding a |
@aryairani you can take a look at 80b459a if you want, it renames |
@pchiusano Pls revert in |
@aryairani thanks for catching that, shoulda verified with grepping, looks good now -
|
This adds the builtin:
And renames
Nat.==
toNat.equal
,Float.==
toFloat.equal
, etc. So it's expected that you'll just use==
everywhere and have TDNR take care of it. An optimizer might put in the monomorphic versions if they're faster, but programmer shouldn't have to sweat that IMO.The implementation works for all types using the same notion of equality used to compute Unison hashes (alpha equivalence of the normalized value). So it compares values structurally. Functions it compares based on their hash, followed by comparison of any partially applied arguments. There's one trick, which is that functions may be applied to themselves, creating a cycle. See
CyclicEq
in Unison.Util for the typeclass that handles this - the general idea is that the equality check needs to keep some state of what it's seen before to break the cycle. And then this is the interesting case of theCyclicEq
implementation forValue
.There's still a few things to fill in, but it seems to work fine and I'd like to merge to keep it from diverging from master (I already had to deal with conflicts).
Known issues:
Universal.==
a more constrained type, so that functions which are parametric get the same free theorems. Something likeforall a . Eq a => a -> a -> Boolean
. This doesn't require full-blown typeclasses. For v1 of Unison, these constraints might be "magic" but for the future we might figure out a way of letting users define their own.==
onEffect
values will currently bomb - this needs filling in, and it requires comparing the IR inside the continuations for equality, which is straightforward but hasn't been done yet. ComparingEffect
values for equality is a pretty weird thing to do (and we had no way of doing it previously) but we should still fill this in for completeness.