当前位置: 动力学知识库 > 问答 > 编程问答 >

integer - Does Haskell provide min/max constants for the range of Int?

问题描述:

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.

网友答案:

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
分享给朋友:
您可能感兴趣的文章:
随机阅读: