[Haskell-cafe] Parsing floating point numbers

Henning Thielemann lemming at henning-thielemann.de
Mon Mar 9 05:44:39 EDT 2009


On Sun, 8 Mar 2009, Felipe Lessa wrote:

> On Sun, Mar 8, 2009 at 9:34 PM, Bjorn Buckwalter
> <bjorn.buckwalter at gmail.com> wrote:
>> (For my current needs the formats accepted by "read" are sufficient,
>> but I want reasonable error handling (Maybe or Either) instead of an
>> exception on bad inputs.)
>
> Why not
>
> readM :: (Monad m, Read a) => String -> m a
> readM str = case [x | (x,"") <- readsPrec 0 str] of
>             [x] -> return x
>             _   -> fail "readM: failed"
>
> Also, I remember seeing this function exported by some module, but I
> don't remember where.

http://www.haskell.org/pipermail/libraries/2008-February/009202.html
http://www.haskell.org/pipermail/haskell-cafe/2008-June/044590.html

Although maybeRead was proposed, I cannot find it:
   http://hackage.haskell.org/packages/archive/base/4.0.0.0/doc/html/Text-Read.html

(Btw. I find it really great, that now the 'base' package documentation 
can be found on Hackage!)


More information about the Haskell-Cafe mailing list