Data.Int

lib/Data/Int.gob

The 64-bit signed integer, which the compiler provides.

type Int = Int
fun toString : fun(Int) -> String

Decimal, with a leading - for a negative number. The digits are peeled off a non-positive copy, because minValue has no positive counterpart to peel them from; % takes the dividend's sign, so each remainder is in -9..0.

fun minValue : fun() -> Int

Int is two's-complement 64-bit, so these are constants -- but the low one cannot be written. -9223372036854775808 lexes as a unary minus applied to 9223372036854775808, which is not an Int, so the literal is rejected before the negation can rescue it. Subtracting from the representable maximum is the way round it.

fun maxValue : fun() -> Int
fun compare : fun(Int, Int) -> Ordering
fun mod : fun(Int, Int) -> Int

Floored, so the result takes the sign of the divisor and is therefore a valid index for every positive b. % is remainder and takes the sign of the dividend; the difference bites exactly where people reach for it, which is bucket selection.

fun abs : fun(Int) -> Int

Panics on minValue(), which has no positive counterpart. That is the trapping behaviour of neg, not an extra rule.

fun addWrapping : fun(Int, Int) -> Int
fun subWrapping : fun(Int, Int) -> Int
fun mulWrapping : fun(Int, Int) -> Int
fun negWrapping : fun(Int) -> Int
fun mulHighUnsigned : fun(Int, Int) -> Int

Returns the high 64 bits of the 128-bit product of a and b, both read as unsigned. With mulWrapping, which is the low 64 bits, it is the whole product.

fun addChecked : fun(Int, Int) -> Option Int
fun subChecked : fun(Int, Int) -> Option Int
fun mulChecked : fun(Int, Int) -> Option Int
fun negChecked : fun(Int) -> Option Int
fun parse : fun(String) -> Option Int

Returns s read as a decimal Int, or None; see parseRadix.

fun parseRadix : fun(String, Int) -> Option Int

Parses s in base radix, which must be in 2..36 (a panic otherwise). Accepts what parse accepts, with digits 0-9 and then letters of either case: an optional sign, then one or more digits, and nothing else -- no 0x prefix, no _, no surrounding space. Returns None for a digit outside the radix or a value outside Int.

fun toStringRadix : fun(Int, Int) -> String

Formats n in base radix (2..36, a panic otherwise) with lowercase letters for the digits above 9 and a leading - for a negative number.

fun sign : fun(Int) -> Int

Returns -1, 0 or 1 as n is negative, zero or positive.

fun floorDiv : fun(Int, Int) -> Int

Returns the quotient of a and b rounded toward negative infinity, which pairs with mod: floorDiv(a, b) * b + mod(a, b) == a. Panics when b is zero, and on floorDiv(minValue(), -1), as / does.

fun divMod : fun(Int, Int) -> (Int, Int)

Returns (floorDiv(a, b), mod(a, b)).

fun gcd : fun(Int, Int) -> Int

Returns the greatest common divisor, never negative; gcd(0, 0) is 0. Panics only when the answer is 2^63, that is, when one argument is minValue() and the other is 0 or minValue().

fun lcm : fun(Int, Int) -> Int

Returns the least common multiple, never negative; zero when either argument is zero. Panics on overflow, as * does.

fun pow : fun(Int, Int) -> Int

Returns base raised to exp. Panics when exp is negative, because the answer is not an Int, and on overflow, as * does; pow(0, 0) is 1.

fun powMod : fun(Int, Int, Int) -> Int

Returns base raised to exp, modulo modulus, in 0..modulus - 1. Panics when exp is negative or modulus is not positive. No intermediate value overflows, whatever the modulus.

fun isqrt : fun(Int) -> Int

Returns the floor of the square root of n. Panics when n is negative.

fun countOnes : fun(Int) -> Int

Returns the number of set bits.

fun leadingZeros : fun(Int) -> Int

Returns the number of zero bits above the highest set bit: 64 for zero.

fun trailingZeros : fun(Int) -> Int

Returns the number of zero bits below the lowest set bit: 64 for zero.

fun and : fun(Int, Int) -> Int
fun or : fun(Int, Int) -> Int
fun xor : fun(Int, Int) -> Int
fun not : fun(Int) -> Int
fun shl : fun(Int, Int) -> Int

All three panic outside 0..63 rather than masking the shift amount, so that x << 64 is a reported bug and not a silent identity. shr is arithmetic: the sign bit replicates. shrUnsigned is logical: zeros come in at the top.

The range is checked here rather than trusted to the primitive, which compiles to a single instruction: arm64 masks the shift amount to six bits, so shifting by 64 would quietly be a shift by zero.

fun shr : fun(Int, Int) -> Int
fun shrUnsigned : fun(Int, Int) -> Int
type Range

The integers from from up to but not including to, as an iterator: empty when from >= to. Exported without its constructor, and its cursor not at all, so a range is only ever made by range.

fun range : fun(Int, Int) -> Range
instance Iterator Range
instance Eq Int
instance Ord Int
instance Add Int
instance Sub Int
instance Mul Int
instance Div Int
instance Rem Int
instance Neg Int
instance Zero Int
instance One Int
instance Show Int
instance Hash Int