Skip to content
heff

int

Int’s bits: an integer’s, as two’s complement has them, its sign extended for ever (as Python’s are) — the and, or and xor of two, and shifts. It has no names of its own but its primitives: its instance, instanceBitwiseInt, is the prelude’s and, shiftL and the others’ at Int, wherever it is imported, by a name or not (import int as Int). (Int is a keyword, so no module is named by it.)

intAnd

intAnd : Int -> Int -> Int

intOr

intOr : Int -> Int -> Int

intXor

intXor : Int -> Int -> Int

intShl

intShl : Int -> Int -> Int

intShr

intShr : Int -> Int -> Int

instanceBitwiseInt

instance instanceBitwiseInt : Bitwise Int

Int’s bits, for what asks for a Bitwise Int: complement x is -x - 1; shiftL x n is x times 2 to the power n, and shiftR x n is x divided by it, rounding down (the bits shifted out lost, the sign shifted in); by a negative n, each is the other by -n.

>>> and 12 10
8
>>> and -1 255
255
>>> and -256 1023
768
>>> or 1536 5
1541
>>> or -8 3
-5
>>> xor 12 10
6
>>> List.map complement [0, 5, -1]
Cons (-1) (Cons (-6) (Cons 0 Nil))
>>> shiftL 1 70
1180591620717411303424
>>> List.map (\n -> shiftL n -1) [5, -5, -1]
Cons 2 (Cons (-3) (Cons (-1) Nil))
>>> List.map (\n -> shiftR n 1) [5, -5, -1]
Cons 2 (Cons (-3) (Cons (-1) Nil))
>>> List.map (\n -> shiftR n -3) [1, -5, 0]
Cons 8 (Cons (-40) (Cons 0 Nil))