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

Boolean versions of bitwise reductions #2821

Open
gergoerdi opened this issue Oct 7, 2024 · 1 comment
Open

Boolean versions of bitwise reductions #2821

gergoerdi opened this issue Oct 7, 2024 · 1 comment

Comments

@gergoerdi
Copy link
Contributor

I've found myself writing both bitToBool . reduceOr and And . reduceAnd a lot, so I realized what I probably want is a combination of the two:

reduceAll :: (BitPack a) => a -> All
reduceAll = All . bitToBool . reduceAnd

reduceAny :: (BitPack a) => a -> Any
reduceAny = Any . bitToBool . reduceOr

This works even better if Any and All itself have BitPack instances, since then this can be used at different layers of structures.

So what do we think about adding these (and also the deriving via Bool instance BitPack All; deriving via Bool instance BitPack Any instances) to clash-prelude?

@christiaanb
Copy link
Member

I'm fine with the semantics, but not yet convinced with the syntax. The other reduceXYZ functions spell out the operators they reduce with, these new function spell out what they reduce to. I wonder if we can can think of something better than reduceToAny and reduceToAll...

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

No branches or pull requests

2 participants