-
Notifications
You must be signed in to change notification settings - Fork 109
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
add relation stuff ala === and /== #196
Conversation
The names |
I considered Control.Arrow; but I weigh that pretty low, since it isn't used much. Other people might weigh that higher. As far as the names being confusing, I agree that they definitely may be. I considered (<<=)hedgehog_pr, but that looks too close to (=<<)base, and its counterpart (>>=)hedgehog_pr is nominally (in the linguistic sense) equivalent to (>>=)base. If anyone has any idea for a better name for those, I certainly wouldn't object. I don't know if it's necessary to continue the trend of three characters - it's possible that they could be english character names. |
They’re also used in Control.Category, so I will also suggest we find different names or operators.
We have not really thought through how many base relations to include as special Hedgehog functions or operators. Now’s probably a good time to think about it.
My gut feeling is that it’s worthwhile wherever we can provide a superior counterexample report by doing so.
… On May 15, 2018, at 5:30 PM, Daniel Cartwright ***@***.***> wrote:
I considered Control.Arrow; but I weigh that pretty low, since it isn't used much. Other people might weigh that higher.
As far as the names being confusing, I agree that they definitely may be. I considered (<<=)hedgehog_pr, but that looks too close to (=<<)base, and its counterpart (>>=)hedgehog_pr is nominally (in the linguistic sense) equivalent to (>>=)base. If anyone has any idea for a better name for those, I certainly wouldn't object. I don't know if it's necessary to continue the trend of three characters - it's possible that they could be english character names.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
@thumphries Would you be in favour of a non-infix operator name? |
ping |
Not a fan of this I'm sorry, I'd like to keep operators to a minimum. I think this is prettier anyway:
Of course it doesn't do the diff, but that's mainly useful for large data structures and I wouldn't have though comparing those for ordering is common enough to include dedicated functions. Maybe you have an example? Also there's no way I'd merge operators which clash with both |
6c5d9dc
to
d36bbea
Compare
I apologize for the tone of the last message I think I was in a bit of a bad mood when I wrote it. I've been considering this PR since I last replied, and I think I found something I'm happy with. I pushed an update to to your branch which renames the operators to use an I would appreciate everyone else's input on this though. @chessai great work on |
d36bbea
to
9985ae0
Compare
As discussed with @amosr @HuwCampbell, I've added function to assert relations directly. Arguably the operators are no longer required, but they do have the advantage of perhaps slightly nicer failure output. Any opinions either way on whether we should keep the operators given the new Failure using operators^ I'm not sure this extra info is a big win?Failure using
|
Keeping the function that @jystic added should be good enough, perhaps I'd consider giving it a different name (I think I've actually never seen Basically we have this already which is good enough
perhaps the proposed The issue I see with adding more operators is that it makes it hard(er) to draw a line; where do we stop adding more assertion-specific stuff? I often see assertions packed on separate libraries (see Groovy Power Assert, Unquote, etc). It's just the Unix philosophy at the end; do one thing and do it well... |
That is what it's called though https://en.wikipedia.org/wiki/Relational_operator |
That's great then 👍 |
|
||
infix 4 @== | ||
|
||
-- | Fails the test if the two arguments provided are equal. |
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.
"not equal"? (And I think the @/=
comment is the wrong way around too)
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.
yeah, you're right oops
i think i might remove the operators anyway after chatting to a few people about this PR
relation x (<=) 'r' | ||
|
||
relate y (<) 87 | ||
relate x (<=) 'r' |
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.
Would appreciate some comments on which name people like best or some other one? The main point of this is to provide a diff, otherwise you'd just use assert and annotate.
Also is the infix style crazy? it's kind of non-haskellish but it does read pretty nice.
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.
no strong opinions, but comparison
is my favourite. I like the infix style, I think it makes the meaning pretty obvious.
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 like diff
and relate
, I like how they sound, diff this with that, relate this with that.
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.
One thing @moodmosaic and I discussed with comparison
is that it's not a verb, like if we could use compare
that would be awesome but it's already taken by Ord
I didn't pick up on any rudeness, so it's ok. Thanks for picking up some work on the branch |
|
||
relate :: (MonadTest m, Show a, Show b, HasCallStack) => a -> (a -> b -> Bool) -> b -> m () | ||
relate = diff | ||
|
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.
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 think diff
sounds more clear than all the others, short and sweet, diff this with that 🚀 🚀 🚀
e0fea5b
to
9c2da54
Compare
Looks like I am still willing to change it if someone has better ideas / good arguments as long as it's prior to the next release. |
👍 |
import Hedgehog.Internal.Source | ||
import Hedgehog.Internal.Property (MonadTest, Diff(..), success, failWith) | ||
import Hedgehog.Internal.Show (valueDiff, mkValue, showPretty) | ||
import Hedgehog.Internal.Source (HasCallStack, withFrozenCallStack) |
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.
Good catch 👍
This PR adds 4 functions, that have similar behaviour to === and /==, except they correspond to different relations.
(<==) ~> (<=)
(>==) ~> (>=)
(>>>) ~> (>)
(<<<) ~> (<)
As for naming, I tried to keep them to three characters while making sure their names didn't conflict with anything popular.
The reason I wanted this is that I was doing some numerical computations and wanted to test that the result of a computation was less than or equal to a particular value.