What is the difference between Int and Integer?
在haskell中,
"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.
源:wikibook Haskell。所以,你可以找到一段温柔的自然数的Haskell的选择。
Int is the type of machine integers,
with guaranteed range at least
-229 to 229 - 1, while Integer is arbitrary precision integers, with
range as large as you have memory for.
http:/ / / / mail.haskell.org pipermail Haskell的咖啡馆/可能/ 009906.html 2005
例如:
然而,
1 2 3 4 5 6 7 8 9 | 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) |
int int是C,这意味着它的值的范围从- 2147483647 to 2147483647,而从整个范围的整数集Z,这是arbitrarily均值,它可以是大的。
1 2 3 |
通知书的int值的文本。
The Prelude defines only the most
basic numeric types: fixed sized
integers (Int), arbitrary precision
integers (Integer), ...
……
The finite-precision integer type Int
covers at least the range [ - 2^29,
2^29 - 1].
从Haskell报告:http:////basic.html www.haskell.org onlinereport #号码
在一个实现,为