Reputation: 15885
Does Haskell provide any constants for knowing the limits of Int
? I understand Int
is platform-dependent, but nevertheless I would like to utilize it and to initialize some values at the extremes in my particular case. The equivalent constants (for instance) in C would be INT_MAX
and INT_MIN
.
Upvotes: 47
Views: 24070
Reputation: 24802
The maximum and minimum bounds for different types are accessed via the Bounded
type-class using the values minBound
and maxBound
.
The values are polymorphic based on the context they are in, so in some cases you might have to explicitly indicate the type if the compiler is unable to infer it. E.g.
x = minBound :: Int
Upvotes: 79