Proposal: Add Text.Read.maybeRead :: Read a => String -> Maybe a

John Meacham john at repetae.net
Fri Feb 8 04:56:27 EST 2008


On Fri, Feb 08, 2008 at 12:17:31AM -0500, David Menendez wrote:
> On Feb 7, 2008 6:12 PM, Ross Paterson <ross at soi.city.ac.uk> wrote:
> > 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.
> 
> I also prefer Maybe to fail. Error strings are only useful if you're
> ignoring them or passing them to the user without interpretation.

say that next time you get a mysterious "fromJust: Nothing" error with
no context, error messages in haskell are quite an issue as is, _any_
useful information is good, passing them on to the user without
interpretation is loads better than not having any clue what went wrong.
It is what you want to do because the fact that it was a 'readM' that
failed is extremely useful for figuring out what went wrong. It is a
straightforward generalization that is very useful pragmatically.

    John

-- 
John Meacham - ⑆repetae.net⑆john⑈


More information about the Libraries mailing list