What is the difference between Int and Integer?
Int
is Bounded
, which means that you can use minBound
and maxBound
to find out the limits, which are implementation-dependent but guaranteed to hold at least [-229 .. 229-1].
For example:
Prelude> (minBound, maxBound) :: (Int, Int)
(-9223372036854775808,9223372036854775807)
However, Integer
is arbitrary precision, and not Bounded
.
Prelude> (minBound, maxBound) :: (Integer, Integer)
<interactive>:3:2:
No instance for (Bounded Integer) arising from a use of `minBound'
Possible fix: add an instance declaration for (Bounded Integer)
In the expression: minBound
In the expression: (minBound, maxBound) :: (Integer, Integer)
In an equation for `it':
it = (minBound, maxBound) :: (Integer, Integer)
"Integer" is an arbitrary precision type: it will hold any number no matter how big, up to the limit of your machine's memory…. This means you never have arithmetic overflows. On the other hand it also means your arithmetic is relatively slow. Lisp users may recognise the "bignum" type here.
"Int" is the more common 32 or 64 bit integer. Implementations vary, although it is guaranteed to be at least 30 bits.
Source: The Haskell Wikibook. Also, you may find the Numbers section of A Gentle Introduction to Haskell useful.