(* I Un type utile pour les ensignants *) (* I.1 *) type note = Math of float | Info of float | Lang of float ;; (* I.2 *) let liste_note = [Math 12.; Math 8.5; Info 18.; Info 12.; Lang 13.; Lang 12.];; (* I.3 *) let affiche (n : note) : unit = (match n with | Math x -> print_float x; print_string " Mathématiques" | Info x -> print_float x; print_string " Informatique" | Lang x -> print_float x; print_string " Langues"); print_newline ();; affiche (Info 7.);; (* I.4 *) let rec afficheliste (ln : note list) : unit = match ln with | [] -> () | t :: q -> affiche t; afficheliste q;; afficheliste liste_note;; (* I.5 *) (* Ici il faut un peu analyser pour avoirunue stratégie. Une possibilité, mais ce n'est pas la seule consiste à écrire une fonction permettant d'extraire les notes de maths d'une liste de notes, et une fonction calculant la moyenne d'une liste de flottants. J'ai mis ici les deux fonctions supplémentaires en définition gloable, mais on peut bien sûr les mettre en définition locale *) let rec extrait_note_math (nl : note list) : float list = match nl with | [] -> [] | (Math x) :: q -> x :: extrait_note_math q | (Info _) :: q -> extrait_note_math q | (Lang x) :: q -> extrait_note_math q;; let moyenne_liste (l : float list) : float = let rec somme l = match l with | [] -> 0. | t :: q -> t +. somme q in somme l /. (float_of_int (List.length l));; let moyenne (nl : note list) : float = moyenne (extrait_note_math nl);; moyenne liste_note;;