Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- class AsBLen a where
- safeBLenSub :: a -> a -> Maybe a
- posIntToBLen :: Int -> a
- wordToBLen# :: Word# -> a
- natToBLen :: Natural -> a
Documentation
Helper definitions for using the given type to store byte lengths.
Byte lengths must be non-negative. Thus, the ideal representation is a
Natural
. However, most underlying types that we use (ByteString
, lists)
store their length in Int
s. By similarly storing an Int
ourselves, we
could potentially improve performance.
I like both options, and don't want to give up either. So we provide helpers via a typeclass so that the user doesn't ever have to think about the underlying type.
For simplicity, documentation may consider a
to be an "unsigned" type. For
example, underflow refers to a negative a
result.
safeBLenSub :: a -> a -> Maybe a Source #
Safe blen subtraction, returning Nothing
for negative results.
Regular subtraction should only be used when you have a guarantee that it won't underflow.
posIntToBLen :: Int -> a Source #
Convert some Int
i
where i >= 0
to a blen.
This is intended for wrapping the output of length
functions.
wordToBLen# :: Word# -> a Source #
Convert some Word#
w
where w <= maxBound
a@ to a blen.
natToBLen :: Natural -> a Source #
Convert some Natural
n
where n <= maxBound
a@ to a blen.