Add readMaybe to Prelude (possibly readEither too), make Haddocks for read more cautionary
read is an easy way to introduce runtime exceptions into programs, but its documentation doesn't sufficiently warn of this danger.
read's safe alternatives,
Text.Read.readEither, are relatively unknown and too hard to find.
- Change the documentation for
readto point out the partiality and to recommend the above alternatives.
3. Improve the documentation for
The haddocks for
read currently read:
readfunction reads input from a string, which must be completely consumed by the input process.
I propose to add the following paragraph:
readwill throw an error if the parse fails. If there's any uncertainty w.r.t. the shape of the input,
readEithershould be used instead.
Regarding point 2 (
readEither), I have some qualms whether
readEither (docs) offers sufficient additional benefit over
readMaybe to also warrant inclusion in
readEither does give additional info on the kind of parse failures, that information is encoded in a
String error message, from which it must be parsed if it is needed in the program.