I was trying to check if a list is sorted in PolyML. The list is not of the built-in type but was defined by me as :
datatype list = empty | cons of int*list;
I don't know how to check for both increasing and decreasing order, so for now I've restricted myself to increasing order (any hint to a more general solution are welcome!).
So my approach is as follows :
local
fun sortedIncreasing (empty) = 1000
| sortedIncreasing (cons(v,l)) = if(v < sortedIncreasing(l)) then v else Int.minInt
in
fun isSortedInc (empty) = true
| isSortedInc (cons(v,l)) = if (sortedIncreasing(cons(v,l)) = Int.minInt) then false else true
end;
First thing Int.minInt
is not of type Int
so I have a type mismatch. How could I solve that?
Secondly I'm afraid this approach is quite naive, how would I solve the problem in a better way?
Thanks for your time, have a good day!