Proposal: Add Text.Read.maybeRead :: Read a => String -> Maybe a
ross at soi.city.ac.uk
Fri Feb 8 11:35:12 EST 2008
On Fri, Feb 08, 2008 at 01:56:27AM -0800, John Meacham wrote:
> On Fri, Feb 08, 2008 at 12:17:31AM -0500, David Menendez wrote:
> > 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,
And that is why people recommend against using functions that throw
errors, like fromJust. But in some monads (and which monad is involved
isn't immediately obvious), readM would be another such function (as is
read, of course).
In contrast, the proposed maybeRead wraps up a solution to a common
problem in a safe way, and requires the caller (who has more information
about the context) to handle failed parses.
More information about the Libraries