-4

i want to write program that can checked a list is sorted or not in ml language program but i am new at this language

i write the below code and seems it works

is there any tips i can use in my ml programing

ml programming language

let issorted x = match x with 
[] -> true
| _::[] -> true
| _::_ -> issorted_helper (x);; 



let rec issorted_helper x = match x with
| [] -> true
| h::t ->
    if h > t
        false
    else
        issorted_helper(t);;
  • This is not a code writing service. Show effort and ask specific programming questions. See [ask] for more. – glennsl Oct 20 '18 at 21:58

1 Answers1

1

That code is not only in OCaml, it's also wrong, so there's little point in translating it.

Write down a case analysis on the structure of the list;

  • The empty list is sorted
  • A list with one element is sorted
  • A list with more than one element is sorted if its first two elements are in order, and the tail of the list is sorted.

Then you translate that to SML.

molbdnilo
  • 64,751
  • 3
  • 43
  • 82