[Haskell-cafe] parsing long numbers
niklas.broberg at gmail.com
Fri Sep 15 09:51:54 EDT 2006
> The problem is that, when I run it with strings containing a number
> more then 10 digit long, I get unexpected integers back:
> *Main> runP number1 "1234567890 and the rest"
> [(1234567890," and the rest")]
> *Main> runP number1 "12345678901 and the rest"
> [(-539222987," and the rest")]
This has nothing to do with your parser, but with the representation
you use. The Int type is bounded by
Prelude> maxBound :: Int
i.e. that's the highest value of Int you could get. So if you just write
Prelude> 12345678901 :: Int
you see that you have the same "problem". The solution is to use the
unbounded type Integer instead of the bounded type Int.
More information about the Haskell-Cafe