To clean up even more, use StateT B.ByteString Maybe.&nbsp; Then the ByteString threading will be invisible, leading to just &quot;liftM2 (,) readI readI&quot;, for suitably defined readI.<br><br><div class="gmail_quote">On Dec 23, 2007 6:45 AM, Bryan O&#39;Sullivan &lt;
<a href="mailto:bos@serpentine.com">bos@serpentine.com</a>&gt; wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="Ih2E3d">
Paulo J. Matos wrote:<br><br>&gt; I guess the latter is the correct guess.<br><br></div>Good guess!<br><br>You can take advantage of the fact that the Maybe type is an instance of<br>the Monad typeclass to chain those computations together, getting rid of
<br>all of the explicit case analysis.<br><br>import qualified Data.ByteString.Char8 as B<br>import Data.Char (isDigit)<br><br>readTwoInts :: B.ByteString -&gt; Maybe ((Int, Int), B.ByteString)<br>readTwoInts r = do<br> &nbsp;(a, s) &lt;- 
B.readInt . B.dropWhile (not . isDigit) $ r<br> &nbsp;(b, t) &lt;- B.readInt . B.dropWhile (not . isDigit) $ s<br> &nbsp;return ((a, b), t)<br><br>Let&#39;s try that in ghci:<br><br> &nbsp;*Main&gt; readTwoInts (B.pack &quot;hello 256 299 remainder&quot;)
<br> &nbsp;Just ((256,299),&quot; remainder&quot;)<br><br>The case analysis is still happening, it&#39;s just being done behind your<br>back by the (&gt;&gt;=) combinator, leaving your code much tidier. &nbsp;(And why<br>is there no explicit use of (&gt;&gt;=) above? &nbsp;Read about desugaring of &quot;do&quot;
<br>notation in the Haskell 98 report.)<br><br>The learning you&#39;ll want to do, to be able to reproduce code such as the<br>above, is about monads.<br><br>Cheers,<br><div><div></div><div class="Wj3C7c"><br> &nbsp; &nbsp; &nbsp; &nbsp;&lt;b
<br>_______________________________________________<br>Haskell-Cafe mailing list<br><a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br><a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">
http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br></div></div></blockquote></div><br>