我想爲SML中的唯一大數製作排序函數,但編譯器一直將我的函數類型設置爲int而不是'a。我怎樣才能明確地告訴編譯器使用IntInf?SML如何顯式設置函數參數類型爲IntInf
這裏是我的代碼:
fun selectsort([a]) = [a]
| selectsort(h::t) =
if (hd(selectsort(t))) < h then hd(selectsort(t))::h::tl(selectsort(t))
else h::selectsort(t);
當我嘗試
fun selectsort([a]) = [a]
| selectsort(l : IntInf list) =
if (hd(selectsort(tl(l)))) < hd(l) then hd(selectsort(tl(l)))::h::tl(selectsort(tl(l)))
else hd(l)::selectsort(tl(l));
它不斷給我 「錯誤:未綁定類型的構造:IntInf」
使用變通方法求解:'if(hd(choicesort(t))+ IntInf.fromInt(0))
2014-12-07 16:08:49