Int package:numhask

A fixed-precision integer type with at least the range [-2^29 .. 2^29-1]. The exact range for a given implementation can be determined by using minBound and maxBound from the Bounded class.
An Integral is anything that satisfies the law:
\a b -> b == zero || b * (a `div` b) + (a `mod` b) == a
>>> 3 `divMod` 2
(1,1)
>>> (-3) `divMod` 2
(-2,1)
>>> (-3) `quotRem` 2
(-1,-1)
Integral classes
Arbitrary precision integers. In contrast with fixed-size integral types such as Int, the Integer type represents the entire infinite range of integers. Integers are stored in a kind of sign-magnitude form, hence do not expect two's complement form when using bit operations. If the value is small (fit into an Int), IS constructor is used. Otherwise IP and IN constructors are used to store a BigNat representing respectively the positive or the negative value magnitude. Invariant: IP and IN are used iff value doesn't fit in IS
The interact function takes a function of type String->String as its argument. The entire input from the standard input device is passed to this function as its argument, and the resulting string is output on the standard output device.
Convert from an Int
fromInteger is special in two ways:
  • numeric integral literals (like "42") are interpreted specifically as "fromInteger (42 :: GHC.Num.Integer)". The prelude version is used as default (or whatever fromInteger is in scope if RebindableSyntax is set).
  • The default rules in haskell2010 specify that constraints on fromInteger need to be in a form C v, where v is a Num or a subclass of Num.
So a type synonym such as type FromInteger a = FromIntegral a Integer doesn't work well with type defaulting; hence the need for a separate class.
Polymorphic version of fromInteger
fromIntegral a == a
Convert to an Int
toIntegral is kept separate from Integral to help with compatability issues.
toIntegral a == a
The print function outputs a value of any printable type to the standard output device. Printable types are those that are instances of class Show; print converts values to strings for output using the show operation and adds a newline. For example, a program to print the first 20 integers and their powers of 2 could be written as:
main = print ([(n, 2^n) | n <- [0..19]])