proposal/RFC: add bSwap to base in Data.Bits
bertram.felgenhauer at googlemail.com
Thu May 16 15:24:53 CEST 2013
thanks for working on this proposal.
> -- | Default implementation for 'bSwap'
> -- This implementation is intentionally naive. Instances are expected to provide
> -- an optimized implementation for their size.
> bSwapDefault :: (Bits a, Num a) => a -> a
> bSwapDefault = go 0
> go !c 0 = c
> go c w = go ((c `unsafeShiftL` 8) .|. (w .&. 0xff)) (w `unsafeShiftR` 8)
This can't be right, since it ignores the bitSize. In fact, from
bSwapDefault 1 = 1 one could conclude that the datatype is 1 byte wide.
bSwapDefault (bSwapDefault 256) = 1 shows that bSwapDefault is not its
(As with bitSize, I don't think that there is a sensible implementation
of bSwap for Integer)
I agree with previous posters that 'bSwap' is a bad name; 'byteSwap'
More information about the Libraries