Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Class for reading bounded values.
Synopsis
- data BoundedRead a
- = NoRead
- | ExactRead a
- | ClampedRead a
- class ReadBounded a where
- readBounded :: String -> BoundedRead a
- readBoundedInteger :: (Bounded a, Read a, Integral a) => String -> BoundedRead a
Documentation
data BoundedRead a Source #
Information about a bounded read.
NoRead | The read failed. |
ExactRead a | The value was successfully read exactly, and did not have to be clamped to a narrower representation. |
ClampedRead a | The value was successfully read, but had to be clamped to a narrower representation because its value was too wide. |
Instances
Eq a => Eq (BoundedRead a) Source # | |
Defined in Text.Read.Bounded (==) :: BoundedRead a -> BoundedRead a -> Bool # (/=) :: BoundedRead a -> BoundedRead a -> Bool # | |
Ord a => Ord (BoundedRead a) Source # | |
Defined in Text.Read.Bounded compare :: BoundedRead a -> BoundedRead a -> Ordering # (<) :: BoundedRead a -> BoundedRead a -> Bool # (<=) :: BoundedRead a -> BoundedRead a -> Bool # (>) :: BoundedRead a -> BoundedRead a -> Bool # (>=) :: BoundedRead a -> BoundedRead a -> Bool # max :: BoundedRead a -> BoundedRead a -> BoundedRead a # min :: BoundedRead a -> BoundedRead a -> BoundedRead a # | |
Read a => Read (BoundedRead a) Source # | |
Defined in Text.Read.Bounded readsPrec :: Int -> ReadS (BoundedRead a) # readList :: ReadS [BoundedRead a] # readPrec :: ReadPrec (BoundedRead a) # readListPrec :: ReadPrec [BoundedRead a] # | |
Show a => Show (BoundedRead a) Source # | |
Defined in Text.Read.Bounded showsPrec :: Int -> BoundedRead a -> ShowS # show :: BoundedRead a -> String # showList :: [BoundedRead a] -> ShowS # |
class ReadBounded a where Source #
Much like the Read
class, but will return (possibly) clamped values.
Typical instances of this class will clamp against minBound
and maxBound
This class is designed to avoid inconsistency problems such as the following:
>>>
read "321" :: Word8
65>>>
read "4321" :: Word8
225>>>
read "-4" :: Word8
252
Using this class, the results are predictable and precise:
>>>
readBounded "321" :: BoundedRead Word8
ClampedRead 255>>>
readBounded "4321" :: BoundedRead Word8
ClampedRead 255>>>
readBounded "-4" :: BoundedRead Word8
ClampedRead 0>>>
readBounded "255" :: BoundedRead Word8
ExactRead 255>>>
readBounded "6" :: BoundedRead Word8
ExactRead 6>>>
readBounded "xxx" :: BoundedRead Word8
NoRead
readBounded :: String -> BoundedRead a Source #
Instances
readBoundedInteger :: (Bounded a, Read a, Integral a) => String -> BoundedRead a Source #
Reads a clamped value for any integer type with the given class constraints.
Useful for implementing a ReadBounded
instance or avoiding one.