This my first topic here please if I commit a mistake explain me
Here is the code I try to compile :
module type OrderedStringFloatFloatFloat =
sig
type t
val compare : t -> t -> int
end
(** module pour la représentation d’une tournée )
module type Tour =
sig
(* une ville )
type city
(* map contenant pour noeud le nom des villes et pour transition la distance entre les deux villes représentées par les noeuds de la map *)
type tour
(** définition d'une map vide *)
val empty : tour
(** test de vacuité d'une map *)
val is_empty : tour -> bool
(** calcul de la distance entre deux villes *)
val distance : city -> city -> float
(** ajout d'une ville dans la map *)
val add_city : city -> tour -> tour
(** ajout d'un chemin pour aller d'une ville A Ă une ville B *)
val add_road : city -> city -> tour -> tour
end
module OrderedStringFloatFloatFloat =
struct
type t = string * float * float * float
let compare t1 t2 = compare t1 t2
end
module MakeMap (X : OrderedStringFloatFloatFloat) =
struct
type city = X.t
module SetString = Set.Make(String)
module MyMap = Map.Make (OrderedStringFloatFloatFloat)
type tour = int * string * SetString.t * SetString.t MyMap.t
let empty = (0, "", SetString.empty, MyMap.empty)
let is_empty t = t = (0, "", SetString.empty, MyMap.empty)
let distance c1 c2 =
let (_, long1, lat1, _) = c1 in
let (_, long2, lat2, _) = c2 in
sqrt ( (long2 -. long1) ** 2. +. (lat2 -. lat1) ** 2. )
let add_city c t =
if MyMap.mem c t then t
else MyMap.add c SetString.empty t
let next_cities c t = MyMap.find c t
let add_road c1 c2 t =
let t1 = add_city c1 t in
let t2 = add_city c2 t1 in
let c1_next = next_cities c1 t2 in
let (s2, _, _, _) = c2 in
let c1_next' = SetString.add s2 c1_next in
let c2_next = next_cities c2 t2 in
let (s1, _, _, _) = c1 in
let c2_next' = SetString.add s1 c2_next in
let t2' = MyMap.add c1 c1_next' t2 in
MyMap.add c2 c2_next' t2'
end
I don’t know how to paste properly my code but there are different problems of unmatching type…
Each time I use a city a problem appears if you know why it will be great to explain it
Thank you !