<div dir="auto">I would guess history has a lot to do with it. The whole readP mechanism is pretty old, and many of our modern conventions hadn't really taken hold yet.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jun 8, 2020, 2:54 PM Andreas Abel <<a href="mailto:andreas.abel@ifi.lmu.de">andreas.abel@ifi.lmu.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> > readIntP :: Num a => a -> (Char -> Bool) -> (Char -> Int) -> ReadP a<br>
<br>
Dunno, but one could guess that people find this function more <br>
convenient to apply, in the spirit of<br>
<br>
readIntP x (('0' <=) .&&. (<= '9')) ((- ord '0') . ord)<br>
<br>
One could always add your function, under a different name.<br>
<br>
They easily convert into each other, using a function like<br>
<br>
boolToMaybe :: Bool -> a -> Maybe a<br>
boolToMaybe True a = Just a<br>
boolToMaybe False _ = Nothing<br>
<br>
On 2020-06-06 01:04, Dannyu NDos wrote:<br>
> Current type signature of readIntP is:<br>
> <br>
> readIntP :: Num a => a -> (Char -> Bool) -> (Char -> Int) -> ReadP a<br>
> <br>
> This seems kinda redundant. It inputs two functions, one checking <br>
> whether a character is valid digit, and the other assigning an integer <br>
> to the digit.<br>
> <br>
> Shouldn't we merge them together to one function? Like this:<br>
> <br>
> importControl.Monad<br>
> importData.Foldable<br>
> importData.Maybe<br>
> importText.ParserCombinators.ReadP<br>
> <br>
> readIntP:: Numa=> a-> (Char-> MaybeInt) -> ReadPa<br>
> readIntP base valDigit = do<br>
> maybeNs <- manyTill (fmap (fmap fromIntegral . valDigit) get) $ do<br>
> str <- fmap (fmap valDigit) look<br>
> casestr of<br>
> []-> return ()<br>
> (Nothing:_) -> return ()<br>
> _ -> pfail<br>
> letn = foldl' (\l r -> casel of<br>
> Nothing -> r<br>
> Just l1 -> fmap (base * l1 +) r<br>
> ) Nothing maybeNs<br>
> guard (isJust n)<br>
> return (fromJust n)<br>
> <br>
> <br>
> _______________________________________________<br>
> Libraries mailing list<br>
> <a href="mailto:Libraries@haskell.org" target="_blank" rel="noreferrer">Libraries@haskell.org</a><br>
> <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br>
> <br>
_______________________________________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org" target="_blank" rel="noreferrer">Libraries@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br>
</blockquote></div>