| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Text.Read.Bounded
- 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.
Constructors
| 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) | |
| Ord a => Ord (BoundedRead a) | |
| Read a => Read (BoundedRead a) | |
| Show a => Show (BoundedRead a) |
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 "999999999999999999999" :: Int3875820019684212735>>>read "9999999999999999999999" :: Int1864712049423024127
Using this class, the results are predictable and precise:
>>>readBounded "999999999999999999999" :: BoundedRead IntClampedRead 9223372036854775807>>>readBounded "9999999999999999999999" :: BoundedRead IntClampedRead 9223372036854775807>>>readBounded "9223372036854775807" :: BoundedRead IntExactRead 9223372036854775807>>>readBounded "1337" :: BoundedRead IntExactRead 1337>>>readBounded "xxx" :: BoundedRead IntNoRead
Methods
readBounded :: String -> BoundedRead a Source
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.