On Sep 29, 2014 11:41 AM, "Edward Kmett" <ekmett@gmail.com> wrote:
>
> It does seem like it should rotate in 1s, but if it does so, what happens when it rotates out something that isn't all 1s into a negative number or all 0s into a positive number?
>
> We'd expect `rotateL n . rotateR n = id = rotateR n . rotateL n` for the finite cases.
>
> but you can't rotate out the digits "up at infinity".
>
> So even this is messy. =/
You're absolutely right. Integer couldn't support that. You could, however, have a Bits instance
newtype RotInteger = RotInteger {number::Integer, atInfinity::Integer}
That would be able to support rotations into and out of the bits "at infinity".
> Ideally we would move rotate/rotateL/rotateR to FiniteBits, but there is a huge upgrade/migration cost associated with that. All user specified instances break in a way that requires CPP and it diverges from the standard further.
Well, the approach taken for bitSize would work here too. Deprecate the three names, leaving them in place. Add three new ones to FiniteBits, using correct but somewhat slow defaults (implementing rotations using shifting and masking). The FiniteBits dictionary is already growing from one member to three, so adding another few should be okay, right?