daily pastebin goal
66%
SHARE
TWEET

Untitled

a guest Feb 22nd, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. type name = string
  2. type age = int
  3. type adress = string
  4. type telephone = int
  5. type contact = (name * age * adress * telephone)
  6.    
  7. let rec exist x liste = match liste with
  8.   |[] -> false
  9.   |e::l -> x = e || exist x l;;
  10.  
  11. let rec add_list x liste = match liste with
  12.   |[] -> x::[]
  13.   |e::l when x < e -> x::liste
  14.   |e::l when x = e -> liste
  15.   |e::l -> e::add_list x l;;
  16.  
  17. let rec remove_list x liste = match liste with
  18.   |[] -> []
  19.   |e::l when x < e -> liste
  20.   |e::l when x = e -> l
  21.   |e::l -> e::remove_list x l;;
  22.  
  23. let rec map f liste = match liste with
  24.   |[] -> []
  25.   |e::l -> f e::map f l;;
  26.  
  27. let rec iter f liste = match liste with
  28.     [] -> ()
  29.   |e::l -> begin
  30.     f e;
  31.     iter f l
  32.   end;;
  33.  
  34. let rec for_all f liste = match liste with        
  35.     [] -> true
  36.   |e::l -> f e && for_all f l;;
  37.  
  38. 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);;
  39.  
  40. 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;;
  41.  
  42. let string_of_char c = String.make 1 c;;
  43.  
  44. let string_apply f string =
  45.   let rec apply i = match i with    
  46.     |0 -> (string_of_char (f string.[0]))
  47.     |i -> apply (i-1)^string_of_char (f string.[i]) in
  48.   apply ((String.length string)-1);;
  49.  
  50. let string_uppercase x  = string_apply upper_case x;;
  51.  
  52. let string_lowercase x = string_apply lower_case x;;
  53.  
  54.  
  55. let convert_first_maj string =
  56.   let length = (String.length string) in
  57.   let rec conversion string x = match x with
  58.     | x when x < length -> (string_of_char(string.[x]))^(conversion string (x+1))
  59.     |_ -> ""
  60.   in (string_of_char(upper_case string.[0]))^conversion string 1 ;;
  61.  
  62.  
  63. let create_contact (string,a,b,c) = (convert_first_maj(string_lowercase(string)),a,b,c);;
  64.  
  65. let rec add_contact (string,a,b,c) liste = match liste with
  66.   |[] -> (string,a,b,c)::[]
  67.   |(str,d,e,f)::l when (str,d,e,f) = (string,a,b,c) -> failwith "le contact est déjà dans la liste"
  68.   |(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
  69.   |(str,d,e,f)::l -> (string,a,b,c)::(str,d,e,f)::l;;
  70.  
  71. let edit_contact string (str,a,b,c) liste =
  72.   let rec f liste2 = match liste2 with
  73.     |[] -> []
  74.     |(str,a,b,c)::l when string = str  -> (string,a,b,c)::l
  75.     |(_,_,_,_)::_ -> failwith "ce contact n'est pas dans l'agenda"
  76.   in add_list (str,a,b,c) (f liste);;
  77.  
  78. let is_good_format map liste = for_all map liste;;
  79.  
  80.  
  81. let rec print_agenda list = match list with
  82.     [] -> ()
  83.   |(prenom,numero,adresse,email)::l -> begin
  84.     print_string prenom;
  85.     print_newline ();
  86.     print_string numero;
  87.     print_newline ();
  88.     print_string adresse;
  89.     print_newline ();
  90.     print_string email;
  91.     print_newline ();
  92.     print_newline ();
  93.   end;
  94.     print_agenda l;;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top