【发布时间】:2019-03-04 19:12:10
【问题描述】:
我正在尝试使用“let in end”在 SML 中创建递归冒泡排序以包含辅助函数。
当谈到为什么它不会打印任何东西时,我很迷茫。
main.sml:
val master = [1,2,3,1,4,2,8,3,2,1]: int list;
fun bubblesort ( x : int list) : int list =
let
fun sort [] = []
| sort [a] = [a]
| sort (a::b::c) = if (a < b) then [a]@sort(b::c) else [b]@sort(a::c)
fun issorted [] = true
| issorted [x] = true
| issorted (x::y::t) = x <= y andalso issorted(y::t)
in
sort x;
if issorted x then x else bubblesort x;
x
end;
val result = bubblesort master
结果:
新泽西州标准 ML v110.78 [构建时间:2017 年 8 月 31 日星期四 03:45:42] val master = [1,2,3,1,4,2,8,3,2,1]:int 列表 val bubblesort = fn :int list -> int list =
【问题讨论】:
标签: sml