<div dir="ltr"><div dir="ltr"><div>Current type signature of readIntP is:</div><div><br></div><div>readIntP :: Num a => a -> (Char -> Bool) -> (Char -> Int) -> ReadP a </div><div><br></div><div>This seems kinda redundant. It inputs two functions, one checking whether a character is valid digit, and the other assigning an integer to the digit.<br></div><div><br></div><div>Shouldn't we merge them together to one function? Like this:</div><div><br></div><div><div style="color:rgb(212,212,212);background-color:rgb(30,30,30);font-weight:normal;font-size:16px;line-height:22px;white-space:pre"><div style="color:rgb(212,212,212);background-color:rgb(30,30,30);font-weight:normal;font-size:16px;line-height:22px;white-space:pre"><div><span style="color:rgb(86,156,214)">import</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(78,201,176)">Control.Monad</span></div><div><span style="color:rgb(86,156,214)">import</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(78,201,176)">Data.Foldable</span></div><div><span style="color:rgb(86,156,214)">import</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(78,201,176)">Data.Maybe</span></div><div><span style="color:rgb(86,156,214)">import</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(78,201,176)">Text.ParserCombinators.ReadP</span></div><br><div><span style="color:rgb(220,220,170)">readIntP</span><span style="color:rgb(212,212,212)"> :: </span><span style="color:rgb(86,156,214)">Num</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(156,220,254)">a</span><span style="color:rgb(212,212,212)"> => </span><span style="color:rgb(156,220,254)">a</span><span style="color:rgb(212,212,212)"> -> (</span><span style="color:rgb(86,156,214)">Char</span><span style="color:rgb(212,212,212)"> -> </span><span style="color:rgb(86,156,214)">Maybe</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(86,156,214)">Int</span><span style="color:rgb(212,212,212)">) -> </span><span style="color:rgb(86,156,214)">ReadP</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(156,220,254)">a</span></div><div><span style="color:rgb(212,212,212)">readIntP base valDigit = </span><span style="color:rgb(197,134,192)">do</span></div><div><span style="color:rgb(212,212,212)">    maybeNs <- manyTill (fmap (fmap fromIntegral . valDigit) get) $ </span><span style="color:rgb(197,134,192)">do</span></div><div><span style="color:rgb(212,212,212)">        str <- fmap (fmap valDigit) look</span></div><div><span style="color:rgb(212,212,212)">        </span><span style="color:rgb(197,134,192)">case</span><span style="color:rgb(212,212,212)"> str </span><span style="color:rgb(197,134,192)">of</span></div><div><span style="color:rgb(212,212,212)">            </span><span style="color:rgb(86,156,214)">[]</span><span style="color:rgb(212,212,212)"> -> return </span><span style="color:rgb(86,156,214)">()</span></div><div><span style="color:rgb(212,212,212)">            (Nothing:_) -> return </span><span style="color:rgb(86,156,214)">()</span></div><div><span style="color:rgb(212,212,212)">            _ -> pfail</span></div><div><span style="color:rgb(212,212,212)">    </span><span style="color:rgb(86,156,214)">let</span><span style="color:rgb(212,212,212)"> n = foldl' (\l r -> </span><span style="color:rgb(197,134,192)">case</span><span style="color:rgb(212,212,212)"> l </span><span style="color:rgb(197,134,192)">of</span></div><div><span style="color:rgb(212,212,212)">            Nothing -> r</span></div><div><span style="color:rgb(212,212,212)">            Just l1 -> fmap (base * l1 +) r</span></div><div><span style="color:rgb(212,212,212)">            ) Nothing maybeNs</span></div><div><span style="color:rgb(212,212,212)">    guard (isJust n)</span></div><div><span style="color:rgb(212,212,212)">    return (fromJust n)</span></div><br></div></div></div></div></div>