[Haskell-cafe] Reading integers

Bulat Ziganshin bulat.ziganshin at gmail.com
Thu Sep 7 02:12:51 EDT 2006

Hello Neil,

Thursday, September 7, 2006, 1:45:03 AM, you wrote:

>> Currently I have a single module that provides reading operations
>> for Integers and Ints. I'm not quite sure what to do with it.

> Get it into base!  Where it is, or what its called is less relevant -
> perhaps entirely decoupled from the Read class, and I wouldn't have
> thought reading octal integers etc was useful - just simple bog
> standard integers. I'd really like just readInt/readInteger in
> Numeric, or Prelude, or possibly even a new Read style module.

i'd just defined the following function, mainly because standard
'read' machinery occupies whole 50 kb in exe-file

readI = foldl f 0
  where f m c | isDigit c  =  fromIntegral (ord c - ord '0') + (m * 10)
              | otherwise  =  error ("Non-digit "++[c]++" in readI")

Best regards,
 Bulat                            mailto:Bulat.Ziganshin at gmail.com

More information about the Haskell-Cafe mailing list