+ deriving Show
+
+instance Eq BitString where
+ a == b = leftRem a' ≡ leftRem b' ∧
+ leftBytes a' ≡ leftBytes b' ∧
+ rightRem a' ≡ rightRem b'
+ where
+ a' = normalise a
+ b' = normalise b
+
+normalise ∷ BitString → BitString
+normalise bs
+ | remLen (leftRem bs) ≡ 8
+ = normalise $ bs {
+ leftRem = remEmpty
+ , leftBytes = L.cons (remByte $ leftRem bs) $ leftBytes bs
+ }
+ | remLen (rightRem bs) ≡ 8
+ = normalise $ bs {
+ rightBytes = L.cons (remByte $ rightRem bs) $ rightBytes bs
+ , rightRem = remEmpty
+ }
+ | otherwise
+ = bs {
+ leftBytes = leftBytes bs `L.append` (L.reverse $ rightBytes bs)
+ , rightBytes = L.empty
+ }