Advertisement
Guest User

Untitled

a guest
Dec 11th, 2018
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. let rec appartient e l =
  2. match l with
  3. [] -> false
  4. |a::_ when a=e -> true
  5. |_::q -> appartient e q
  6. ;;
  7.  
  8. let rec elimine_doublon l =
  9. match l with
  10. [] -> []
  11. |a::q -> if (appartient a q) then elimine_doublon q
  12. else a::(elimine_doublon q)
  13. ;;
  14.  
  15. let rec second l =
  16. match l with
  17. [] -> []
  18. |(x,y)::reste -> x::second reste;;
  19. ;;
  20.  
  21.  
  22. module type tFILE = sig
  23. type 'a t
  24. val vide : 'a t
  25. val enfile : 'a -> 'a t -> 'a t
  26. val defile : 'a t -> 'a t
  27. val sommet : 'a t -> 'a
  28. val est_vide : 'a t -> bool
  29. end
  30.  
  31.  
  32. module FILE : tFILE = struct
  33.  
  34. type 'a t = 'a list
  35. let vide = []
  36.  
  37. let enfile = fun a -> fun file -> match file with
  38. | [] -> [a]
  39. | x::reste -> x::reste @ [a];;
  40.  
  41. let defile = fun file -> match file with
  42. | [] -> failwith "empty file"
  43. | x::reste -> reste;;
  44.  
  45. let sommet = fun file -> match file with
  46. | [] -> failwith "empty file"
  47. | x::reste -> x;;
  48.  
  49. let est_vide = fun file -> file = [];;
  50. end
  51.  
  52.  
  53. module type tFILE_AUX = functor (F:tFILE) -> sig
  54. val enfile_elems : 'a list -> 'a F.t -> 'a F.t
  55. end
  56.  
  57. module FILE_AUX : tFILE_AUX = functor(F:tFILE) -> struct
  58.  
  59. let rec enfile_elems liste file = match liste with
  60. |[] -> file
  61. |x::reste -> F.enfile x (enfile_elems reste file)
  62. end
  63.  
  64. module type tGRAPH = sig
  65.  
  66. (* graphe paramétré par le type de ses sommets *)
  67. type 's t
  68. (* construit un graphe en fournissant la liste des arcs
  69. (origine, destination) présents dans le graphe *)
  70. val cons : ('s * 's) list -> 's t
  71. (* renvoie la liste (sans répétition) de tous les sommets impliqués
  72. dans le graphe *)
  73. val sommets : 's t -> 's list
  74. (* pour un sommet donné et un graphe donné,
  75. renvoie la liste (sans répétition) des sommets successeurs *)
  76. val succ : 's -> 's t -> 's list
  77. end
  78.  
  79. module GRAPH : tGRAPH = struct
  80. type 's t = ('s * 's)list;;
  81.  
  82. let cons = function
  83. |[]->[]
  84. |(x1,x2)::reste -> (x1,x2)::reste ;;
  85.  
  86. let rec sommets = function
  87. |[]->[]
  88. |(x1,x2)::reste -> if (appartient x1 (second reste)) then sommets reste else x1::(sommets reste);;
  89.  
  90. let rec succ s = function
  91. |[]->[]
  92. |(x1,x2)::reste -> let aux = if x1 = s then x1::(succ s reste) else succ s reste
  93. in elimine_doublon aux;;
  94.  
  95. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement