let rec somme (l: int list) : int = match l with [] -> 0 | x::reste -> x+(somme reste);; let somme_carre (l:int list) : int = somme (List.map (fun x -> x*x) l);; let rec somme_carre_2 (l:int list) : int = match l with [] -> 0 |x::reste -> (x*x)+(somme_carre_2 reste);; let rec produit (l:int list) : int = match l with [] -> 1 |x::reste -> x * (produit reste);; let rec existe (l:'a list) (predicat : 'a -> bool) : bool = match l with [] -> false |x::reste -> (predicat x) || (existe reste predicat);; let rec tous (l:'a list) (predicat : 'a -> bool) : bool = match l with [] -> true |x::reste -> (predicat x) && (tous reste predicat);; let somme_schema (l: int list) : int = List.fold_right (fun element -> fun historique -> element+historique) l 0;; let somme_carre_schema (l: int list) : int = List.fold_right (fun e -> fun h -> (e*e)+h) l 0;; let produit_schema (l:int list) : int = List.fold_right (fun e -> fun h -> e*h) l 1;; let existe_schema (l:'a list) (p:'a -> bool) : bool = List.fold_right (fun e -> fun h -> (p e)||h) l false;; let tous_schema (l:'a list) (p:'a -> bool) : bool = List.fold_right (fun e -> fun h -> (p e)&&h) l true;; let compte_positif (l:int list) : int = List.fold_right (fun e -> fun h -> h+(if e>0 then 1 else 0)) l 0;;i let maximum (l:int list) : int = match l with x::reste -> List.fold_right (fun e->fun h-> if e>h then e else h) l x;; let tri (l:int list) : int list = let rec inserer (elem:int ) (lloc:int list) : int list = match lloc with [] -> [elem] |x::reste -> if (elem>x) then elem::x::reste else x::(inserer elem reste) in List.fold_right (fun e-> fun h-> (inserer e h) ) l [];; (*fonction qui récupère le dernier élément d'une liste non vide *) let rec dernier (l:'a list) : 'a = match l with [e] -> e | x::s -> dernier s;; let valeur_cumules (l: int list) : int list = List.fold_left (fun valc -> fun e -> if (valc=[]) then [e] else valc@[e+(dernier valc)]) [] l;;