Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type name = string
- type age = int
- type adress = string
- type telephone = int
- type contact = (name * age * adress * telephone)
- let rec exist x liste = match liste with
- |[] -> false
- |e::l -> x = e || exist x l;;
- let rec add_list x liste = match liste with
- |[] -> x::[]
- |e::l when x < e -> x::liste
- |e::l when x = e -> liste
- |e::l -> e::add_list x l;;
- let rec remove_list x liste = match liste with
- |[] -> []
- |e::l when x < e -> liste
- |e::l when x = e -> l
- |e::l -> e::remove_list x l;;
- let rec map f liste = match liste with
- |[] -> []
- |e::l -> f e::map f l;;
- let rec iter f liste = match liste with
- [] -> ()
- |e::l -> begin
- f e;
- iter f l
- end;;
- let rec for_all f liste = match liste with
- [] -> true
- |e::l -> f e && for_all f l;;
- let upper_case x = if int_of_char(x) < 97 && int_of_char (x) > 122 then x else char_of_int (int_of_char (x) -32);;
- let lower_case x = if int_of_char(x) > 64 && int_of_char (x) < 91 then char_of_int (int_of_char (x) +32) else x;;
- let string_of_char c = String.make 1 c;;
- let string_apply f string =
- let rec apply i = match i with
- |0 -> (string_of_char (f string.[0]))
- |i -> apply (i-1)^string_of_char (f string.[i]) in
- apply ((String.length string)-1);;
- let string_uppercase x = string_apply upper_case x;;
- let string_lowercase x = string_apply lower_case x;;
- let convert_first_maj string =
- let length = (String.length string) in
- let rec conversion string x = match x with
- | x when x < length -> (string_of_char(string.[x]))^(conversion string (x+1))
- |_ -> ""
- in (string_of_char(upper_case string.[0]))^conversion string 1 ;;
- let create_contact (string,a,b,c) = (convert_first_maj(string_lowercase(string)),a,b,c);;
- let rec add_contact (string,a,b,c) liste = match liste with
- |[] -> (string,a,b,c)::[]
- |(str,d,e,f)::l when (str,d,e,f) = (string,a,b,c) -> failwith "le contact est déjà dans la liste"
- |(str,d,e,f)::l when ((lower_case str.[0]),d,e,f) < ((lower_case string.[0]),a,b,c) -> (str,d,e,f)::add (string,a,b,c) l
- |(str,d,e,f)::l -> (string,a,b,c)::(str,d,e,f)::l;;
- let edit_contact string (str,a,b,c) liste =
- let rec f liste2 = match liste2 with
- |[] -> []
- |(str,a,b,c)::l when string = str -> (string,a,b,c)::l
- |(_,_,_,_)::_ -> failwith "ce contact n'est pas dans l'agenda"
- in add_list (str,a,b,c) (f liste);;
- let is_good_format map liste = for_all map liste;;
- let rec print_agenda list = match list with
- [] -> ()
- |(prenom,numero,adresse,email)::l -> begin
- print_string prenom;
- print_newline ();
- print_string numero;
- print_newline ();
- print_string adresse;
- print_newline ();
- print_string email;
- print_newline ();
- print_newline ();
- end;
- print_agenda l;;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement