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

Steve Lihn stevelihn at gmail.com
Wed Dec 26 22:14:59 EST 2007


Just curious -- how can this be done in Arrows instead of Manad/T? Or can it?

On Dec 26, 2007 6:42 AM, Benja Fallenstein <benja.fallenstein at gmail.com> wrote:
> On Dec 23, 2007 1:44 PM, Isaac Dupree <isaacdupree at charter.net> wrote:
> > parseHeader3 :: BS.ByteString -> Maybe (Int, Int)
> > parseHeader3 bs = do
> >    (x, rest) <- BS.readInt $ BS.dropWhile (not . isDigit) bs
> >    (y, _) <- BS.readInt $ BS.dropWhile (not . isDigit) rest
> >    return (x, y)
>
> But that version still itches! :-)
>
> This is what it sounds like to me:
>
> parseHeader :: BS.ByteString -> Maybe (Int,Int)
> parseHeader = evalStateT $ liftM2 (,) parseInt parseInt where
>    parseInt = StateT $ BS.readInt . BS.dropWhile (not . isDigit)
>
> - Benja
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>


More information about the Haskell-Cafe mailing list