readMaybe parses a String into a value whose type has a Read instance. It returns Just for successful conversion and Nothing when conversion fails. section 8.1.1
ghci> import Text.Read ghci> :t readMaybe readMaybe :: Read a => String -> Maybe a ghci> readMaybe "100" :: Maybe Int Just 100 ghci> readMaybe "abc" :: Maybe Int Nothing
The type signature and GHCi examples show polymorphic parsing, successful Int conversion, and failed conversion. section 8.1.1
Converting CSV fields
A CSV field arrives as Text, so T.unpack supplies the String expected by readMaybe. A successful result becomes IntValue; failure falls back to TextValue, while an empty field becomes NullValue. section 8.1.1 section 8.1.1
Parsing integers
A parser first consumes digit characters, then calls readMaybe. Just returns the parsed Integer; Nothing is converted into a parser failure with an explanatory message. section 12.1.5
Use readMaybe when conversion should remain explicit and recoverable:
- Annotate the result when inference needs a concrete target such as Maybe Int. section 8.1.1
- Handle Nothing as ordinary invalid input rather than allowing a failed conversion to continue. section 8.1.1 section 12.1.5
