-
Notifications
You must be signed in to change notification settings - Fork 154
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
New function: runUntil #1940
New function: runUntil #1940
Conversation
-> Signal dom a | ||
-- ^ 'Signal' we want to sample for the condition | ||
-> IO () | ||
runUntil check s = value `seqX` putStrLn msg |
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.
Perhaps sampleUntil
? Given that we already have sample
and sampleN
.
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.
Oh that's nice, +1
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 sample
and sampleN
return samples, runUntl
doesn't return them. I agree that it does sample the signal, to be able to do the testing, but if it were called sampleUntil
I would think it would return the list of samples until the test was true.
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.
Although I guess that'd mean it'd have to return [a]
, so perhaps this is better after all.
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.
It could be worth having both? I can see a sampleUntil
that returns the values also being useful
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.
For a single test bench, P.takeWhile not $ sample testBench
is pretty okay already, it's when you have multiple test benches that runUntil
becomes a prety nice shorthand. So I had always intended to steer the reader towards that kind of use, and then totally forgot to put it in once I was actually writing the doc...
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 always have Haskell's
Prelude
imported qualified underP
in myclashi
sessions
To take a harsh stance: if you need to have Prelude
from base
imported in clashi
, Clash.Prelude
isn't doing it's job well enough. For me the pattern of P.takeWhile not $ sample testBench
motivates a sampleUntil
function being included because that's friendlier to beginners who may not be aware there's a second prelude they can import
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 are doing enough already... I was not aware, but you can just do
> takeWhile not $ sample testBench
:-)
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.
Hmm okay, so the situation isn't as bad as I thought. In that case I guess it's not so bad to not have sampleUntil
, although maybe it would still be a nice touch given sampleN
is basically just a synonym for take
after sample
and sampleUntil
is a synonym for takeWhile (not . p)
for some p
after sample
I leave it to your own preference 🙂
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 a sampleUntil
with the documentation pointers you suggested on Slack are a good addition.
290622b
to
ab137b3
Compare
`runUntil`, a function to sample a signal until it returns a value that satisfies the user-given test. It is a convenience function that, among others, allow easy running of a `testBench` style function in Haskell simulation, logging assertion failures to stderr.
ab137b3
to
727519b
Compare
runUntil
, a function to sample a signal until it returns a value thatsatisfies the user-given test. It is a convenience function that, among
others, allow easy running of a
testBench
style function in Haskellsimulation, logging assertion failures to stderr
Still TODO: