1
我稍微困惑,因为编译器告诉我,1, [5;2]
不是这两种情况下一个元组:插入元组进入ocaml的名单
(1,[5;2])::[6,[5;1]; 2,[16;1]]
这不起作用
(为什么?)1,[5;2]::[6,[5;1]; 2,[16;1]]
我问这个,因为我需要解决我的问题:
type node = int
type edge = node * node
type graph = (node * node list) list
let has_node g n = List.exists ((=) n) g
let insert_node g n =
if has_node g n then g else (n, [])::g (*here is where the compiler complains*)