Data.Bits can still have default implementations for testBit, bit, and popCount by using -XDefaultSignatures
In commit f99cee0 of the base package, the Num constraint was removed from the Bits class. Because the default implementations of testBit, bit, and popCount required Num, the same commit made them external functions instead.
We can still have default implementations for these if we use the -XDefaultSignatures GHC extension:
#ifdef __GLASGOW_HASKELL__
default bit :: Num a => Int -> a
bit = bitDefault
default testBit :: Num a => a -> Int -> Bool
testBit = testBitDefault
default popCount :: Num a => a -> Int
popCount = popCountDefault
#endif
Whether we want to do this or not, I'm not sure.
Pro:
- This is more convenient.
- This may prevent people from encountering runtime errors in existing code that does not have bit, testBit, and popCount implementations, where the author forgot to compile with -Wall .
Con:
- Users get away with writing less portable code, so those who do wish to use non-GHC will have more support work to do.
The attached patch adds defaults for testBit, bit, and popCount, for GHC only. It does not update the documentation, though, so "Minimal complete definition" as-is would be misleading.
P.S.: This ticket is for GHC 7.6.1-rc1. That version tag is not available, though.
Trac metadata
Trac field | Value |
---|---|
Version | |
Type | FeatureRequest |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Runtime System |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |