Types Can';不理解OCaml trie类型声明
我试图理解人们是如何用OCaml编写trie的。我在网上找到了一个例子: 它定义了一个映射:Types Can';不理解OCaml trie类型声明,types,ocaml,Types,Ocaml,我试图理解人们是如何用OCaml编写trie的。我在网上找到了一个例子: 它定义了一个映射: module CharMap = Map.Make(Char) 然后定义trie的类型: (* count of members of the set that end at this node * mapping from next char => children *) type trie = Node of int * trie CharMap.t 这里是我的问题:什么是tri
module CharMap = Map.Make(Char)
然后定义trie的类型:
(* count of members of the set that end at this node * mapping from
next char => children *)
type trie = Node of int * trie CharMap.t
这里是我的问题:什么是trie CharMap.t
?我想这是某种地图,但我不知道它是什么
感谢您的代码片段,我猜是
trie CharMap。t
是一个映射,其中键是字符,值是递归定义的trie
类型。要扩展rgrinberg的答案,在OCaml中,类型构造函数在其参数之后。因此您有了int list
,这是一个int列表。这里有一个类型构造函数CharMap.t
,它构造了键类型为char
的映射。所以int CharMap.t
将是从char
s到int
s的映射。trie CharMap.t
的含义是完全类似的,除了(正如rgrinberg指出的)这是类型trie
的递归使用之外。这与树的定义类似,因为树的节点中包含的内容本身就是树。在这里,trie中包含的内容本身就是尝试。trie CharMap.t是从Char到trie数据类型的映射类型。
这将使用参数类型。比如说,
输入'param paired_with_int=int*'param
然后,您可以按如下方式创建指定类型:
类型特定的_对=浮点对_与_int