-
-
Notifications
You must be signed in to change notification settings - Fork 20
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 special treatment of non-compliant values in lte and equals #147
Conversation
53b5571
to
b51561e
Compare
b51561e
to
2a4e265
Compare
We should update the type signatures of |
In which way? |
Oh! I see. Yes. |
5005a78
to
b5b7fe5
Compare
I can't figure out the signature. Hindley Milner is not versatile enough to cleanly separate garbage inputs from desired inputs. The best I can come up with is this overloaded function. equals :: Setoid a => (a, a) -> Boolean
equals :: (a, AnythingBut a) -> Boolean |
We could say that the function wants |
I suggest using |
@davidchambers Updated. |
//. Returns `true` if its arguments are of the same type and equal according | ||
//. to the type's [`fantasy-land/equals`][] method; `false` otherwise. | ||
//. to the type's [`fantasy-land/equals`][] method. Returns `false` for | ||
//. inputs of differing types. |
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.
I don't think this change is necessary, as we already include the clause if its arguments are of the same type.
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.
But false
otherwise is too broad: When a user provides two values of the same type that don't have Setoid, the function throws.
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.
We do not typically document the behaviour of a function when applied to an argument outside its domain. The description of S.trim
, for example, does not consider the possibility of application to a non-string value.
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.
So you'd prefer to remove the false
otherwise part altogether, and treat the special treatment of inputs of differing types as an undocumented "feature", or simply garbage?
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.
when applied to an argument outside its domain
Supplying two values of differing types is within the domain of the function. So is supplying two Setoids of the same type. Anything else isn't.
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.
I do not see how Setoid a => (a, a) -> Boolean
permits inputs of differing types. 🤔
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.
But the real signature is:
equals :: Setoid a => (a, a) -> Boolean
equals :: (a, AnythingBut a) -> Boolean
Remember..? But you said that is not pedagogical.
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.
The function has a special code path to facilitate the latter overload.
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.
That makes these inputs part of the domain in my book.
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.
You yourself said:
We can document in other ways how the function behaves when given values of different types. -- #147 (comment)
That's what I'm trying to do here.
eb8f229
to
82f4007
Compare
82f4007
to
97f8522
Compare
Instead of arbitrarily returning false, these functions now throw when given invalid (without the proper type class) input.
97f8522
to
d9272cd
Compare
This PR competes with and so closes #154
Instead of arbitrarily returning false, these functions now throw when
given invalid (without the proper type class) input.