On Saturday 21 June 2008, Don Stewart wrote:
>       maybeRead :: Read a => String -> Maybe a
>       maybeRead s = case reads s of
>           [(x, "")] -> Just x
>           _         -> Nothing

Note, if you want to match the behavior of read, you'll probably want 
something like:

    maybeRead :: Read a => String -> Maybe a
    maybeRead s = case reads s of
        [(x, str)] | all isSpace str -> Just x
        _                            -> Nothing

Otherwise, trailing spaces will yield a bad parse.

-- Dan
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to