A graph in OCaml can be defined in this way
type 'a graph = Gr of ('a * 'a) list;;
let myGraph = Gr[(1,2);(1,3);(1,4);(2,6);(3,5);(4,6);(6,5);(6,7);(5,4)];;
但是,如果我想在边缘附加权重,我该怎么办?
然而,表示图表的最佳方式是什么?
答案 0 :(得分:1)
为什么不加一下呢?
type weight = float (* or whatever *)
type 'a graph = Gr of ('a * 'a * weight) list