}
deriving Show
+-- | /O(n)/ The bitstrings must have finite lengths to test the
+-- equality.
instance Eq BitString where
a == b = leftRem a' ≡ leftRem b' ∧
leftBytes a' ≡ leftBytes b' ∧
∧
remNull (rightRem bs)
--- | /O(n)/ Return the number of bits in a 'BitString'.
+-- | /O(n)/ @'length' bs@ returns the number of bits in @bs@. @bs@
+-- must have a finite length.
length ∷ Integral n ⇒ BitString → n
length bs
= fromIntegral $ ( fromIntegral (remLen $ leftRem bs)
, rightRem = remEmpty
}
--- | /O(n)/ Convert a 'BitString' into 'L.ByteString', padding
--- incomplete bytes to single bytes with necessary 0's at their
--- MSB. Thus the following equation does not hold when the length of
--- 'BitString' isn't multiple of 8.
+-- | /O(n)/ @'toByteString' bs@ converts @bs@ into 'L.ByteString',
+-- padding incomplete bytes to single bytes with necessary 0's at
+-- their MSB. Thus the following equation does not hold when the
+-- length of @bs@ isn't multiple of 8.
--
-- > fromByteString . toByteString = id
--
-- But the following always holds true.
--
-- > toByteString . fromByteString = id
+--
+-- Note that @bs@ must have a finite length.
toByteString ∷ BitString → L.ByteString
toByteString bs
= L.concat [ remToStr $ leftRem bs