PROPOSAL: Export "readEither" from Text.Read

Christian Maeder Christian.Maeder at dfki.de
Mon Dec 12 19:27:24 CET 2011


Am 12.12.2011 16:24, schrieb Ben Millwood:
> On Thu, Dec 8, 2011 at 10:39 PM, Iavor Diatchki
> <iavor.diatchki at gmail.com>  wrote:
>> Hello,
>>
>> when writing simple String parsers, I find implementing this function
>> over and over:
>>
>> readEither :: Read a =>  String ->  Either String a
>
> The only thing that bothers me about this is the fact that the error
> is a String; I don't think that's a very good type for errors, because
> only humans can really effectively interpret it. I don't know whether
> it's worth introducing a new sum type just for the different kinds of
> read error.

http://www.haskell.org/ghc/docs/latest/html/libraries/base-4.4.1.0/src/Text-Read.html

The current error messages are a bit stupid, anyway. An ambiguous parse 
could be avoided by (arbitrarily) returning the first match. Instead of 
"no parse" I would expect a proper char position of my error, but that's 
difficult to extract from the Read class.

> Regardless, readMaybe is definitely a good idea, so +1 for that.

Indeed, readMaybe is a good idea and quite enough.

C.





More information about the Libraries mailing list