41 lines
983 B
OCaml
41 lines
983 B
OCaml
|
(* Exercice 1 *)
|
|||
|
(*1)*)
|
|||
|
() ;;
|
|||
|
(*2)*)
|
|||
|
let c2() = 2;;
|
|||
|
(*3)*)
|
|||
|
let rien a = ();;
|
|||
|
(*4)*)
|
|||
|
let hello() = print_string "Hello World !\n";;
|
|||
|
|
|||
|
(*Exercice 2*)
|
|||
|
|
|||
|
let rec itere f n a = match n with
|
|||
|
| 0 -> a
|
|||
|
| _ -> f (itere f (n-1) a);;
|
|||
|
itere sin 3000 1.;;
|
|||
|
|
|||
|
(* Exercice 3*)
|
|||
|
(*1) : La fonction List.length retourne la longueur d'une liste.*)
|
|||
|
let rec longueur liste = match liste with
|
|||
|
| [] -> 0
|
|||
|
| _ -> (longueur (List.tl liste)) + 1;;
|
|||
|
|
|||
|
longueur [1;2;3];;
|
|||
|
(*2) : La fonction List.map applique une fonction <20> chaque <20>l<EFBFBD>ment d'une liste.*)
|
|||
|
let rec mapper f liste = match liste with
|
|||
|
| [] -> []
|
|||
|
| _ -> (f (List.hd liste))::(mapper f (List.tl liste));;
|
|||
|
|
|||
|
mapper sin [1.;2.;3.];;
|
|||
|
(*3)*)
|
|||
|
|
|||
|
|
|||
|
let rec concatener listes = match longueur listes with
|
|||
|
| 0 -> []
|
|||
|
| 1 -> List.hd listes
|
|||
|
| 2 -> (List.hd listes)@(List.hd (List.tl listes))
|
|||
|
| _ -> concatener ([(List.hd listes)@(List.hd (List.tl listes))]@(List.tl (List.tl listes)));;
|
|||
|
concatener [[1;2;3];[2;1;3];[4;5;1;3];[1]];;
|
|||
|
concatener [];;
|
|||
|
List.concat [];;
|