[Haskell-cafe] Reading integers

Lennart Augustsson lennart at augustsson.net
Thu Sep 7 08:56:03 EDT 2006


What about negative numbers?

Also, don't use (ord c - ord '0'), it doesn't work with Unicode digits.
That's why there is a digitToInt function.

	-- Lennart

On Sep 7, 2006, at 02:12 , Bulat Ziganshin wrote:

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



More information about the Haskell-Cafe mailing list