
21 Jun
2008
21 Jun
'08
5:37 p.m.
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