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

David Menendez dave at zednenem.com
Fri Feb 8 00:17:31 EST 2008


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.

-- 
Dave Menendez <dave at zednenem.com>
<http://www.eyrie.org/~zednenem/>


More information about the Libraries mailing list