Skip to content
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

Merged
merged 1 commit into from
Sep 30, 2021
Merged

New function: runUntil #1940

merged 1 commit into from
Sep 30, 2021

Conversation

DigitalBrains1
Copy link
Member

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

Still TODO:

  • Write a changelog entry (see changelog/README.md)
  • Check copyright notices are up to date in edited files

-> Signal dom a
-- ^ 'Signal' we want to sample for the condition
-> IO ()
runUntil check s = value `seqX` putStrLn msg
Copy link
Member

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.

Copy link
Contributor

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

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Contributor

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

Copy link
Member Author

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...

Copy link
Contributor

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 under P in my clashi 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

Copy link
Member Author

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

:-)

Copy link
Contributor

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 🙂

Copy link
Member Author

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.

clash-prelude/src/Clash/Explicit/Signal.hs Outdated Show resolved Hide resolved
clash-prelude/src/Clash/Explicit/Signal.hs Outdated Show resolved Hide resolved
clash-prelude/src/Clash/Explicit/Signal.hs Outdated Show resolved Hide resolved
clash-prelude/src/Clash/Explicit/Signal.hs Outdated Show resolved Hide resolved
`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.
@DigitalBrains1 DigitalBrains1 enabled auto-merge (squash) September 30, 2021 14:32
@DigitalBrains1 DigitalBrains1 merged commit 5f632b4 into master Sep 30, 2021
@DigitalBrains1 DigitalBrains1 deleted the run_until branch September 30, 2021 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants