I'm trying to create a recursive bubble sort in SML using 'let in end' to contain helper functions.
I'm rather lost when it comes to why it won't print anything.
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
Result:
Standard ML of New Jersey v110.78 [built: Thu Aug 31 03:45:42 2017] val master = [1,2,3,1,4,2,8,3,2,1] : int list val bubblesort = fn :int list -> int list =
