-
Notifications
You must be signed in to change notification settings - Fork 376
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
Is really necessary specify "No parts of <...> value should be checked"? #303
Comments
I think the law is there to serve as a more direct deterrent for unlawful implementations. Specifically, I also believe that the law is redundant with regards to preventing these bad implementations, and in fact, overly restrictive otherwise. Sanctuary breaks this law in multiple ways:
In my view, both of these cases should be allowed. |
It is indeed to prevent that, also "were" should be "are". If someone comes up with a better phrasing of this, then I don't see why it shouldn't be amended. |
The point here is that seems that these kind of laws are too much restrictive:
and redundant (it seems that each algebraic type that is not "No parts of <...> value should be checked" compliant, it's not compliant with other of its laws). |
Let's take simplest functions form the spec: In Purescript similar function for Array will have signature like this: if you have function like this you can't do anything to the input (you can't perform any "checking") except passing it to some other function or storing it in some other value. it's because it can be of any type and when you say your function works for all types it must work for all types otherwise compiler will reject you implementation. In js there is no type system, and this kind of restriction is just specified verbally in fantasy land. for example the Array.prototype.of = function(val) {
if (val == []) {return []} else return [val]
// or
if (val == null) {return []} else return [val]
} Which will be valid if that restriction is removed from the spec and we don't want such implementations as it would result in unlawful behavior. We could use
Regarding Sanctuary breaking this law, i don't think it quite counts:
|
But if there's some other law that the implementation would be breaking, isn't this one then redundant? I think that's the main point. I know that FantasyLand is written as a specification with little room for exposition, but I would rather see this as a note, or perhaps as Again, is there any reason that this should be unlawful?: class Just extends Maybe {
...
map(f) {
const r = f(this.val)
return r === null ? Maybe.of(r) : Maybe.of(r);
}
}``` |
The inspection happening in the example you provided has no observable effect, therefore I consider it to be valid implementation. Having
|
I guess I'd simply like to see a section in the prefix similar to the "Terminology", "Type Signatures", etc. ones, something like:
... and then simply use |
That sounds good to me! Unless others disagree on this, I think a way forward would be to open a PR with changes discussed here. |
See #311. |
It is not unlawful because both of the branches of the ternary operator return the same value ( The given implementation is equivalent to: class Just extends Maybe {
...
map(f) {
return Maybe.of( f(this.val) );
}
} There is no inspection happening, which is exactly what the specification determines. |
I would like to point that specs talk about inspection (checked), not about inspection with observable effect. Do specs really need to talk about what means obserbable effect when there are other more clear laws which avoid unlawful specs? For example, the
Of course,
Of course,
Of course,
This is the law I started talking about. In my opinion too much restrictive and composition functor law avoids wrong implementations (see my first post).
Of course, if it were not like that, the type of |
Hi!
After reading #210, I still don't understand why these kind of law are needed. The topic starts talking about "No parts of
b
return value should be checked. But, finally, it concludes that the implementations that perform this kind of checks are breaking other laws.For example:
This implementation breaks
No parts of f's return value should be checked
. However, it is also breaking the composition law:Then, I wonder if
No parts of f's return value should be checked
is a really necessary law. For me it's a weird law because is talking about the implementation. For example these two implementations of Maybe:and
behave the same and are identity and composition law compliant. However, the second breaks the
No parts of f's return value should be checked
and is not functor lawful. It doesn't make sense for me.Cheers!
The text was updated successfully, but these errors were encountered: