
On Thu, Feb 07, 2008 at 10:46:48AM -0800, Don Stewart wrote:
This function is typically defined once per project. So its about time this safe variant of 'read' made it into the base.
maybeRead :: Read a => String -> Maybe a maybeRead s = case reads s of [(x, "")] -> Just x _ -> Nothing
I think this is a good idea, though I normally write the equivalent of maybeRead :: Read a => String -> Maybe a maybeRead s = case reads s of [(x, rest)] | all isSpace rest -> Just x _ -> Nothing and would prefer not to generalize it to any monad. fail is a wart, not a design pattern.
Consideration period: 1 week.
I think that's too short, and the recent fashion of 2 weeks is too short, even for an uncontroversial change. Some people aren't here continuously, but I'd still like to get their input.