proposal/RFC: add bSwap to base in Data.Bits

Vincent Hanquez tab at
Thu May 16 08:59:28 CEST 2013


I'm trying to expose some byte swapping (bSwap) capabilities in base, namely
operation to allow to swap endianness on word{16,32,64}, i.e.:

  bswap16 :: Word16 -> Word16
  bswap16 a = (a `shiftR` 8) .|. (a `shiftL` 8)

I'ld want to propose to extends Bits to do so generically:

  class Bits a where
    bSwap : a -> a

I'm attaching a patch that do as explained, and add a default implementation
for bSwap, so that compatibility is assured for existing instances.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: base-bswap.patch
Type: text/x-diff
Size: 2996 bytes
Desc: not available
URL: <>

More information about the Libraries mailing list