Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
List 将元组插入Ocaml列表_List_Ocaml - Fatal编程技术网

List 将元组插入Ocaml列表

List 将元组插入Ocaml列表,list,ocaml,List,Ocaml,我有点困惑,因为编译器告诉我1[5;2] 不是两种情况下的元组: (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

我有点困惑,因为编译器告诉我
1[5;2]
不是两种情况下的元组:

(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*)

::
的优先级高于
。因此,第二行定义的值与第一行定义的值不同。相反,它定义了
1,([5;2]:[6[5;1];2[16;1]])

代码的问题是,
has_node
希望列表
g
包含
n
类型的元素,而
(n,[])
则是另一种类型