ML has a type of integers. Fine; but how large is the underlying representatinon? 16 bit? 32 bit? 64 bit?
So I read this page about SML and based—indirectly—on that reading, here’s how I found out …
… in SML:
$ rlwrap sml Standard ML of New Jersey v110.69 [built: Mon Jun 8 14:15:08 2009] - Int.precision; [autoloading] [library $SMLNJ-BASIS/basis.cm is stable] [autoloading done] val it = SOME 31 : int option - Int.minInt; val it = SOME ~1073741824 : int option - Int.maxInt; val it = SOME 1073741823 : int option
… and in PolyML:
$ rlwrap poly Poly/ML 5.2 Release > Int.precision; val it = NONE : Int.int option > Int.minInt; val it = NONE : Int.int option > Int.maxInt; val it = NONE : Int.int option
Some comments:
- SML autoloads the package providing Int.precision as needed. Don’t worry about it.
- The option type-former in int option indicates that the function might return NONE or a value SOME x where x:int.
- PolyML has infinite-precision arithmetic as default, so Int.minInt returns NONE because there is no least integer.
- SML has 31 bit integers by default—which gives you between plus and minus one billion. Thus Int.minInt returns SOME ~1073741824.
(The extra bit is reserved by the implementation to indicate whether a word is an integer or a pointer.)
PolyML is another ML implementation, and a rather nice one. If you are fortunate enough to be using a Debian-based Linux, you can get it by typing in
sudo apt-get install polyml
You can also type in
sudo apt-get install xaos