-
Notifications
You must be signed in to change notification settings - Fork 6
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
breaks object equality #57
Comments
This actually makes sense and is not a bug like #54 (though it might be annoying). If I have
A proxied/contracted object is not the same as the original object. That's just how the proxy system works, you are not allowed to override equality. |
So the proxy spec says that proxy objects have their own identity. That is fine, however proxies are an implementation detail of contracts.coffee. This is very annoying: I have code that works, but when I place a contract on a function it no longer works. If there is a way for contracts not to have side effects on the code, we should figure it out. Ideas:
|
Good point. So probably the best bet is to weaken the kinds of checks that object contracts do. Humm...perhaps we could have two types of object contracts, one that just does flat checks and doesn't wrap its object and another that wraps its object breaking equality but protecting invariants. Perhaps by default obj contracts nested in fun contracts are the first order check and if you specifically wrap an object in a contract you get the wrapped version? |
I am not sure what the default should be. I lean towards no side effects by default, but I haven't noticed this before. I think this is because I hardly ever perform object equality. Instead, I normally check for equality of members of objects. Your suggestion sounds appealing (if I understand it correctly), but risks inconsistent behavior that requires documentation and not being entirely satisfactory. I think we need to consider adding a syntax that lets the user control it at least when defining a named object contract. |
Yeah, I agree; we need distinct syntax for the different behaviors. Some bikeshedding: have the current # only checks that the param has the id prop
f :: ({id: Str}) -> Str
f = ...
# wraps the param
f :: (obj{ id: Str }) -> Str
f = ...
# double curlies?
f :: ({{ id: Str }}) -> Str
# shorten obj to o?
f :: (o{ id: Str }) -> Str |
if I see f :: (proxy{ id: Str }) -> Str
f :: ( P{ id: Str } ) -> Str
# a special symbol?
f :: ( ^{id: Str} ) -> Str
# like an array it just does simple checks
f :: ( [ id: Str ] ) -> Str |
This issue seems similar to: #54
An equality test broke for me on the same object but one was wrapped in a contract.
In Chrome, the object normally shows up as:
When it has been placed under a contract, I don't see
Object
.The text was updated successfully, but these errors were encountered: