We have a list such as [1,2,7,5,3,2,8,9] and we want to create a list that includes lists of groups of those numbers so that each group does not have decreasing order of its numbers. For example for the above list the answer is [[1,2,7],[5],[3],[2],[8,9]] because 1<2<7(one group, no decreasing order) [5],[3] different groups because 5>3 etc. I wrote this program in ml and it shows this error :
Elaboration failed: Type clash. An expression of type "'a" cannot have type "'a list" because of circularity.
Where is the error in my code ? Any help will be appreciated! My code is this :
fun final_listify (h::t) =
let
fun listify [] acc = acc
| listify (h::t) [[]] = [[h]]
| listify (h::t) ((h1::t1)::rest) =
if h >= h1 then listify t ((h::h1::t1)::rest)
else listify t (h::(h1::t1)::rest);
in
listify (h::t) [[]]
end;