2011-10-18 22 views
3

我想與SML中的大整數在這個環節上進行計算,通過像戰俘功能:如何在SML中使用IntInf或LargeInt?

http://www.standardml.org/Basis/int-inf.html#IntInf:STR:SPEC

可是我怎麼去用這個「圖書館」?


UPDATE:

感謝您的回答。我知道了。我還與

Control.Print.intinfDepth := 10000; 

我做我自己的戰俘功能IntInfs(和它的作品)這樣的改變限制打印:

fun power 0 = IntInf.toLarge 1 
    | power n = IntInf.toLarge 2 * power(n-1); 

回答

3

這取決於你使用哪種實現,但一般您需要將您詮釋的轉換LageInt/InfInf類型與Int.toLarge

(* will be types as an IntInf *) 
val aa = 10983298432984329843298432984329843298432987987987432987987987432987 
val a = IntInf.pow(aa,10); 

(* explicit type as if some other constraint had enforced this*) 
val b = 10 : int 
val c = Int.toLarge b; 

val d = IntInf.pow(c, b); 

變量aa可能不會在你的解釋進行解析。這取決於你使用的是什麼。我已經在poly和mlton中測試過它。

當上述得到類型(通過用-show-基礎標誌mlton給出):

val a: intInf 
val aa: intInf 
val b: int32 
val c: intInf 
val d: intInf