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 -> IntintOr
intOr : Int -> Int -> IntintXor
intXor : Int -> Int -> IntintShl
intShl : Int -> Int -> IntintShr
intShr : Int -> Int -> IntinstanceBitwiseInt
instance instanceBitwiseInt : Bitwise IntInt’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 108>>> and -1 255255>>> and -256 1023768>>> or 1536 51541>>> or -8 3-5>>> xor 12 106>>> List.map complement [0, 5, -1]Cons (-1) (Cons (-6) (Cons 0 Nil))>>> shiftL 1 701180591620717411303424>>> 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))