I’ve been coding my own bit-vectors (represented as strict tuples over Word64 values) as an exercise in time and space optimizations and wanted to define instances of the Bits typeclass for them, but then I noticed that the class declaration for Bits is defined as follows:
class Num a => Bits a
To workaround this, I’m defining a fake Num instance as well, made up mostly of error-valued functions as a hack, but this doesn’t feel right…
What was the rationale of depending on the Num type-class for bit-wise operations? Wouldn’t it make more sense to be able to have Bits instances independen from having to declare a Num instance as well?
Bitsdepends onNum, becauseNumprovides numeric literals and negation, which are used in the default methods forBits, like so:If there were no default methods, you could imagine getting away without the
Numconstraint.