fork(1) download
  1. let encode comp list =
  2. let rec aux idx fst acc = function
  3. | [] -> [] (* Can only be reached if original list is empty *)
  4. | [x] ->
  5. (match fst with
  6. | (fidx, fval) ->
  7. if (idx - fidx) > 1 (* only intervals of length 2 or more*)
  8. then (fidx, fval, idx, x) :: acc
  9. else acc
  10. | _ -> acc)
  11. | a :: (b :: _ as t) ->
  12. if comp a b then
  13. aux (idx+1) fst acc t
  14. else
  15. let st = Some (idx,a) in
  16. (match fst with
  17. | (fidx, fval) ->
  18. if (idx - fidx) > 1 then
  19. aux (idx+1) st ((fidx, fval, idx, a) :: acc) t
  20. else
  21. aux (idx+1) st acc t
  22. | _ -> _)
  23. in
  24. List.rev (aux 0 (0,0) [] list);;
  25.  
  26. Printf.printf "%A" (encode (<) [60;61;62;50;51;52;80;79;78]);;
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
File "prog.ml", line 22, characters 13-14:
Syntax error
stdout
Standard output is empty