(*Maximum*) let max2 a b = if a >. b then a else b;; let max3 a b c = max a (max b c);; (*Contr�le de type*) let equal x y = if x = y then true else false ;; (* equal : 'a -> 'a -> bool = *) let Entre3et5 x = (x > 3) & (x < 5) ;; (* Entre3et5 : int -> bool = *) let Test0 x y = if (Test1 x) then 3 else 4;; (* The value identifier Test1 is unbound. *) (* ou bien si on d�clare Test1 avant Test0 *) (* Test1 x: This expression has type int, but is used with type bool.*) let Test1 x = if Entre3et5 x = false then 1 else 2 ;; (* Test1 : int -> int = *) let Test2 x = if equal (Entre3et5 x) false then true else false ;; (* Test2 : int -> bool = *) let Test3 x y = let z = if(Test1 x) then 3 else 4 in z +. y;; (* Test1 x : This expression has type int, but is used with type bool.*) let Test4 x y = if equal x y then Test1 x else Test2 y;; (* Test2 y : This expression has type bool,but is used with type int.*) let Test5 x = if not (Entre3et5 x) then 1 else 2 ;; (* Test5 : int -> int = *) let Test6 x y = if Entre3et5 x then not(Entre3et5 y);; (* This expression has type unit,but is used with type bool.*) let Test7 x y = x + if(x>=y) then "bonjour" else "au revoir";; (* This expression has type string, but is used with type int.*) (*Fonctions bool�ennes*) (function x -> not(not x));; (* booleen --> booleen *) (* x |--> x *) (function x -> (x or (not x)));; (* booleen --> booleen *) (* x |--> vrai *) (function x -> function y -> (not x) or y);; (* booleen X booleen --> booleen *) (* (vrai,vrai) |--> vrai *) (* (vrai,faux) |--> faux *) (* (faux,vrai) |--> vrai *) (* (faux,faux) |--> vrai *) (function x -> function y -> (not x) & (not y));; (* booleen X booleen --> booleen *) (* (vrai,vrai) |--> faux *) (* (vrai,faux) |--> faux *) (* (faux,vrai) |--> faux *) (* (faux,faux) |--> vrai *) (function x -> function y -> (not(not y)) or (not x));; (* booleen X booleen --> booleen *) (* (vrai,vrai) |--> vrai *) (* (vrai,faux) |--> faux *) (* (faux,vrai) |--> vrai *) (* (faux,faux) |--> vrai *) let ouex a b = if a then not b else b;; let ouex a b = not (Equivalent a b);; let equivalent a b = if a then b else not b;; let NOU a b = not a & not b ;; let NET a b = not a or not b ;; let IMP a b = not a or b ;; let IMP2 a b = not ( a & not b) ;; let EQUIV a b = not ( a & not b) & not ( b & not a) ;; let EQUIV2 a b = (not a or b) & (not b or a);; (*Ann�e bissextile*) let bissextile a = if (a mod 4) = 0 then if (a mod 100) = 0 then if (a mod 400)= 0 then true else false else true else false ;; (*Aire d'une couronne*) let pi = acos (-1) ;; let aire_cercle r = pi *. r *. r ;; let aire_couronne r1 r2 = if r2 >. r1 then aire_cercle r2 -. aire_cercle r1 else aire_cercle r1 -. aire_cercle r2 ;; (*Facture*) let facturation1 q p = if p *. q > 100. then p *. q else 1.1 *. p *. q ;; let facturation2 q p = if p *.q > 100. then p *. q else if 0.1 *. p *. q < 2. then p *. q +. 2. else 1.1 *. p *. q ;; (*Nombre de solutions r�elles d'une �quation du second degr�*) let nb_sol a b c = let discriminant = b *. b -. 4. *. a *. c in if discriminant > 0. then 2 else if discriminant < 0. then 0 else 1 ;; (*Imp�t sur le revenu*) let calc_revenu_net_imposable revenu frais = let apres_premier_abattement = 0.8 *. revenu in let forfait = 0.1 *. apres_premier_abattement in if forfait > frais then 0.9 *. apres_premier_abattement else apres_premier_abattement -. frais;; let calc_quotient_familial revenu_net_imposable nb_part = revenu_net_imposable /. nb_part;; let calc_impot_brut quotient_familial revenu_net_imposable nb_part = if quotient_familial <= 25890. then 0.0 else if quotient_familial <= 50930. then revenu_net_imposable *. 0.105 -. nb_part *. 2718.45 else if quotient_familial <= 89650. then revenu_net_imposable *. 0.24 -. nb_part *. 9594. else if quotient_familial <= 145160. then revenu_net_imposable *. 0.33 -. nb_part *. 17662.5 else if quotient_familial <= 236190. then revenu_net_imposable *. 0.43 -. nb_part *. 32178.5 else if quotient_familial <= 291270. then revenu_net_imposable *. 0.48 -. nb_part *. 43988. else revenu_net_imposable *. 0.54 -. nb_part *. 61464.2;; let impot revenu frais nb_part = let revenu_net_imposable = calc_revenu_net_imposable revenu frais in let quotient_familial = calc_quotient_familial revenu_net_imposable nb_part in let impot_brut = calc_impot_brut quotient_familial revenu_net_imposable nb_part in if impot_brut >=. 3300. then impot_brut else let decote = 3300. -. impot_brut in let final = impot_brut -. decote in if final < 400. then 0. else final;;