views:

207

answers:

3

Is there a Java BigInt equivalent for Standard ML? The normal int type throws an exception when it overflows.

+4  A: 

Yes, see the IntInf structure.

zvrba
A: 

The BigInt-equivalent is called LargeInt. See these lecture notes to see some functions on how to convert between int (aka Int) and LargeInt.

harms
From the SML basis library: "If an implementation provides the `IntInf` structure, then `LargeInt` must be the same structure as `IntInf` (viewed through a thinning `INTEGER` signature). Otherwise, if `LargeInt` is not the same as `Int`, then there must be a structure `Int<N>` equal to `LargeInt`." In other words, `LargeInt` isn't guaranteed to be unbounded (though SML/NJ's is), but it's more portable than `IntInf` (which isn't required to exist).
ephemient
I advise against using LargeInt. You'd much rather have a compile-time failure than an unexpected overflow at run time. (Although running out of memmory has a charm all its own.)
Norman Ramsey
A: 

Well, int puts a nasty limit on stuff like calculating permutations. SML needs a large numeric datatype thats more natural to use.