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

Sterling Clover s.clover at gmail.com
Fri Feb 8 00:56:11 EST 2008


readM for an arbitrary monad with a standard error message++. not  
necessarily because I believe this is the right or even the one true  
way to do this per se., but rather because this is how Data.Map etc.  
handle failure on lookups, etc. Given that read apparently trims  
trailing whitespace, I also approve of adding that to this function.  
My argument here is that uniform and expected behavior should be a  
stronger goal of libraries than the ugly rails notion of  
"configuration by convention." As such, generalizing to an arbitrary  
monad is more uniform and common than simply using a Maybe instance  
(and provides a strict superset of functionality to boot).  
Furthermore, I agree with the dislike of fail, and agree that it  
should be moved to MonadFail or MonadZero or such. However, I also  
think that even if this were to happen in a major revamp (Haskell' or  
whatever) that it would be more appropriate to have a generalized  
readM than not. in fact, as a whole, there's really no reason the  
libraries should err on the size of giving less generality rather  
than more.

--Sterl.

p.s. Actually, the fact that read doesn't act like readM by default  
strikes me as a bug, but not one that can reasonably be resolved with  
the libraries as they stand. As the general sentiment seems to go,  
total base libraries ftw. The more direct the path for haskell  
newcomers to come over the benefits of strong type-safety in all  
instances, the better.

On Feb 7, 2008, at 10:52 PM, John Meacham wrote:

> On Thu, Feb 07, 2008 at 03:20:31PM -0500, Jeff Polakow wrote:
>> Why not allow an arbitrary monad?
>>
>> readM :: (Monad m, Read a) => String -> String -> m a
>> readM errMsg s = case reads s of
>>     [(x, "")] -> return x
>>     _ -> fail errMsg
>
> Yes. I strongly support this, this routine has been in my GenUtil  
> for a
> long time as is hella useful. Though, I wouldn't give it an error
> message argument and just let it have something descriptive like  
> "readM:
> no parse" as in my other reply.
>
>         John
>
>
> -- 
> John Meacham - ⑆repetae.net⑆john⑈
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://www.haskell.org/mailman/listinfo/libraries



More information about the Libraries mailing list