【发布时间】:2014-12-08 01:39:29
【问题描述】:
我正在尝试为 SML 中的唯一大数创建一个排序函数,但编译器一直将我的函数类型设置为 int 而不是 'a.如何明确告诉编译器使用 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(selectsort(t)) + IntInf.fromInt(0)) < h + IntInf.fromInt(0) then hd(selectsort(t))::h::tl(selectsort(t))
标签: sorting sml largenumber selection-sort