[Haskell-cafe] Re: Comments on reading two ints off Bytestring
chaddai.fouche at gmail.com
Mon Dec 24 07:52:28 EST 2007
2007/12/24, Paulo J. Matos <pocm at soton.ac.uk>:
> On Dec 24, 2007 11:55 AM, Paulo J. Matos <pocm at soton.ac.uk> wrote:
> > On Dec 23, 2007 12:44 PM, Isaac Dupree <isaacdupree at charter.net> wrote:
> > >
> > > -- this should work too
> > > parseHeader3 :: BS.ByteString -> Maybe (Int, Int)
> > > --note accurate type signature, which helps us use Maybe failure-monad,
> > > --although losing your separate error messages
> > Oh gee, I just noticed that my type sig is in fact not correct. How
> > come GHC doesn't complain?
Your type is correct.
> > > 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???
> Ok, got it, I'm not returning a maybe. That's it then.
> Still, the first question remains... what happens to (x, rest) if
> BS.readInt returns Nothing.
Your function return a Maybe (Int,Int), (x,y) is of type (Int,Int).
If readInt return a nothing, the whole funtion will return a Nothing
per (>>=) instance definition.
More information about the Haskell-Cafe