Proposal: Add readMaybe (and possibly readEither) to Prelude, make Haddocks for read more cautionary

Yitzchak Gale gale at sefer.org
Wed Dec 28 19:29:37 UTC 2016


Henning Thielemann wrote:
> I do not like to add more stuff to Prelude. It is pretty cumbersome to write
> packages that equally work for Prelude versions before and after this
> change. In order to avoid preprocessor clutter I tend to import explicitly
> from Prelude or other 'base' modules. You can easily import these functions
> from Text.Read.

That's all true. After an earlier period of continual change to the
Prelude, we have had a period where the Prelude was effectively
frozen, for this reason.

But after some years of a frozen Prelude, many people feel that
we have accumulated cruft, and that now the Prelude needs to
be updated again to match modern practice. A sudden upheaval
doesn't seem prudent, but incremental changes like this one that
give a lot of benefit for little cost seem worthwhile.

> Generally I think that the Read class is overused. Strictly spoken, it would
> be only sensible to parse Haskell expressions with it, but actually it is
> mostly used for parsing user input like numbers.

Nowadays parsing numbers can use the more efficient and
correct combinators in places like Data.Text.Read and
Data.Attoparsec. But there are other common uses of Read
(when performance does not matter), such as:

o Debugging and test suites
o Easy serialization
o An input data file format that parses for free

Regards,
Yitz


More information about the Libraries mailing list