[Haskell-cafe] Re: Comments on reading two ints off Bytestring

Brandon S. Allbery KF8NH allbery at ece.cmu.edu
Mon Dec 24 15:03:40 EST 2007

On Dec 24, 2007, at 13:18 , Isaac Dupree wrote:

> Paulo J. Matos wrote:
>> On Dec 23, 2007 12:44 PM, Isaac Dupree <isaacdupree at charter.net>  
>> wrote:
>>> parseHeader3 bs = do
>>>    (x, rest) <- BS.readInt $ BS.dropWhile (not . isDigit) bs
>>>    (y, _) <- BS.readInt $ BS.dropWhile (not . isDigit) rest
>>>    return (x, y)
>> What happens then if the first BS.readInt return Nothing???
> when the first one returns Nothing, the whole expression becomes  
> Nothing without examining the later parts of computation (as  
> Chaddaï said)

One thng that's not obvious here is that pattern match failure  
translates to a call to "fail", which in the definition of Monad for  
Maybe becomes Nothing.

(Hm.  Isaac:  I thought that translation only happened for the "do"  
sugar, and in the direct case you must do it yourself or Haskell  
raises the "incomplete pattern match" exception?)

brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery at kf8nh.com
system administrator [openafs,heimdal,too many hats] allbery at ece.cmu.edu
electrical and computer engineering, carnegie mellon university    KF8NH

More information about the Haskell-Cafe mailing list