[Haskell-cafe] Parsing floating point numbers

Felipe Lessa felipe.lessa at gmail.com
Sun Mar 8 20:50:18 EDT 2009

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.



More information about the Haskell-Cafe mailing list