let rec aux idx
fst acc
= function | [] -> [] (* Can only be reached if original list is empty *)
| [x] ->
| (fidx, fval) ->
if (idx - fidx) > 1 (* only intervals of length 2 or more*)
then (fidx, fval, idx, x) :: acc
else acc
| _ -> acc)
| a :: (b :: _ as t) ->
if comp a b then
else
let st = Some (idx,a) in
| (fidx, fval) ->
if (idx - fidx) > 1 then
aux (idx+1) st ((fidx, fval, idx, a) :: acc) t
else
aux (idx+1) st acc t
| _ -> _)
in
Printf.printf
"%A" (encode
(<) [60;61;62;50;51;52;80;79;78]);;
bGV0IGVuY29kZSBjb21wIGxpc3QgPQogIGxldCByZWMgYXV4IGlkeCBmc3QgYWNjID0gZnVuY3Rpb24KICAgICAgfCBbXSAtPiBbXSAoKiBDYW4gb25seSBiZSByZWFjaGVkIGlmIG9yaWdpbmFsIGxpc3QgaXMgZW1wdHkgKikKICAgICAgfCBbeF0gLT4KICAgICAgCShtYXRjaCBmc3Qgd2l0aAogIAkJIHwgKGZpZHgsIGZ2YWwpIC0+CgkgIAkJaWYgKGlkeCAtIGZpZHgpID4gMSAgICAgICAgICAgICAgICAgKCogb25seSBpbnRlcnZhbHMgb2YgbGVuZ3RoIDIgb3IgbW9yZSopCgkgIAkJdGhlbiAoZmlkeCwgZnZhbCwgaWR4LCB4KSA6OiBhY2MKCSAgCQllbHNlIGFjYwoJCSB8IF8gLT4gYWNjKQogICAgICB8IGEgOjogKGIgOjogXyBhcyB0KSAtPiAKCQlpZiBjb21wIGEgYiB0aGVuIAoJIAkJYXV4IChpZHgrMSkgZnN0IGFjYyB0CgkJZWxzZQoJICAJCWxldCBzdCA9IFNvbWUgKGlkeCxhKSBpbgoJICAJCShtYXRjaCBmc3Qgd2l0aAoJICAJCSB8IChmaWR4LCBmdmFsKSAtPgoJICAgIAkJaWYgKGlkeCAtIGZpZHgpID4gMSB0aGVuCgkgICAgICAJCQlhdXggKGlkeCsxKSBzdCAoKGZpZHgsIGZ2YWwsIGlkeCwgYSkgOjogYWNjKSB0CgkgICAgCQllbHNlCgkgICAgICAJCQlhdXggKGlkeCsxKSBzdCBhY2MgdAoJICAJCSB8IF8gLT4gXykKCSAgaW4KICBMaXN0LnJldiAoYXV4IDAgKDAsMCkgW10gbGlzdCk7OwogClByaW50Zi5wcmludGYgIiVBIiAoZW5jb2RlICg8KSBbNjA7NjE7NjI7NTA7NTE7NTI7ODA7Nzk7NzhdKTs7