
7 Feb
2008
7 Feb
'08
10:48 p.m.
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
Consideration period: 1 week.
May I suggest 'readM'? It is just the obvious generalization of the 'readIO' that is in the Prelude, that it isn't generalized is a bug in the prelude IMHO. (and it is signifigantly more useful)
readM :: (Monad m,Read a) => String -> m a readM s = case reads s of [(x, "")] -> return x _ -> fail "readM: no parse"
John -- John Meacham - ⑆repetae.net⑆john⑈