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

Optimise even and odd? #179

Open
benhutchison opened this issue Oct 10, 2024 · 0 comments
Open

Optimise even and odd? #179

benhutchison opened this issue Oct 10, 2024 · 0 comments

Comments

@benhutchison
Copy link

benhutchison commented Oct 10, 2024

Just something to consider..

even and odd are defined generically as combinators rather than as typeclass methods.

even :: (P.Eq a, Integral a) => a -> P.Bool
even n = n `rem` (one + one) P.== zero

However, for most hardware-backed Integral types Int, Int64 etc there will be a likely much more efficient implementation by bit testing the lowest bit in the register.

If these were overridable on the Integral class, it might permit this specialization.

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

1 participant