Quantcast
Channel: Active questions tagged ocaml - Stack Overflow
Viewing all articles
Browse latest Browse all 531

Sorting a list of lists according to length of sublists

$
0
0
let rec insert cmp e = function   | [] -> [e]   | h :: t as l ->     if cmp e h <= 0 then e :: l     else h :: insert cmp e tlet rec sort cmp = function  | [] -> []  | h :: t -> insert cmp h (sort cmp t)let length_sort lists =  let lists = List.map (fun list -> List.length list, list) lists in  let lists = sort (fun a b -> compare (fst a) (fst b)) lists in  List.map snd lists;;

I want to know how work this fun a b -> compare (fst a) (fst b),compare return 1 or -1, and what will give as variable to sort?and List.map snd lists will remove the first element of every list in the lists?


Viewing all articles
Browse latest Browse all 531

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>