An Int
in Haskell should support at least the range [-2^29 .. 2^29-1]
, but it can also be larger. The exact size will depend on both the compiler you are using and the architecture you are in. (For more information, see the 2010 Haskell Report , the latest standard for the Haskell language.)
With the GHC on a 64-bit machine, you will have a range of [-2^63..2^63 - 1]
. But even on a 32-bit machine, I believe the GHC range gives you a little more than a strict minimum (presumably [-2^31..2^31 - 1]
).
You can check what the actual border with maxBound
and minBound
:
> maxBound :: Int 9223372036854775807
Differences between implementations arise because the definition of a language explicitly allows them to implement these types in different ways. Personally, I would continue to use GHCi
, just considering this, because GHC
is by far the most likely compiler you will use. If you encounter a large number of inconsistencies, you can look at them in the standard or ask someone (like here!); think of it as a learning process;).
In this regard, the standard is flexible, allowing various compilers and architectures to optimize their code in different ways. I assume (but not 100% sure) that the minimum range is set taking into account the 32-bit system, and also allows the compiler to use a pair of bits from the base 32-bit value for its own internal purposes, such as easily distinguishing numbers from pointers. (Something that I know, Python and OCaml, at least, do.) GHC does not need to do this, so it provides full 32 or 64 bits suitable for its architecture.
source share