From 998022df1d02ab23cbbb45a65e80b6e9d38c6ae4 Mon Sep 17 00:00:00 2001 From: Louis Date: Thu, 26 Oct 2023 20:56:11 +0200 Subject: [PATCH] vault backup: 2023-10-26 20:56:10 --- Code CAML.md | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/Code CAML.md b/Code CAML.md index a7fbce5..5ac6b5e 100644 --- a/Code CAML.md +++ b/Code CAML.md @@ -2,10 +2,28 @@ let rec insert_post x f = function | [] -> Failwith "x cannot be inserted" | e::t -> if f e then e::x::t else y::insert_post x f t;; +val insert_post: 'a -> ('a -> bool) -> 'a list -> 'a list = -let pos_max lst = let x = 1 in match lst with +let rec pos_max lst = let x = 1 in match lst with | [] -> invalid_arg "post_max: empty list" - | e::[] -> e - | e1::e2::t -> if e2 > e1 then - x = x + 1; - e2::pos_max else e1::t;; + | e::[] -> x + | e1::e2::t -> + if e2 > e1 then + begin + x = x + 1; + e2::pos_max t; + end; + else + e1::pos_max t;; + +let pos_max lst = + if lst = [] then + failwith "pos_max: empty list" + else + let rec pmr mval mpos cpos = function + | [] -> mpos + | e::t -> + if e > mval then + pmr e cpos (cpos + 1) t + else + pmr mval mpos (cpos + 1) t