Recursion OCaml:如何使用相同类型的Set参数创建归纳类型
在OCaml中,我可以定义以下类型:Recursion OCaml:如何使用相同类型的Set参数创建归纳类型,recursion,types,set,ocaml,Recursion,Types,Set,Ocaml,在OCaml中,我可以定义以下类型: type mytype = Base of int | Branch of (int * (collection -> collection)) and collection = mytype list 假设我基于每个构造函数的int值定义了一个比较函数,那么如何将集合转换为集合而不是列表?这是需要使用递归模块的情况之一。事实上,你可以看到,这是一个实际的例子,你得到的。因此,应该采取以下措施: module rec Myty
type mytype = Base of int
| Branch of (int * (collection -> collection))
and collection = mytype list
假设我基于每个构造函数的int值定义了一个比较函数,那么如何将
集合
转换为集合
而不是列表
?这是需要使用递归模块的情况之一。事实上,你可以看到,这是一个实际的例子,你得到的。因此,应该采取以下措施:
module rec Mytype : sig
type t = Base ...
val compare : t -> t -> int
end = struct
type t = Base ...
let compare v0 v1 = ...
end
and Collection : Set.S with type elt = Mytype.t
= Set.Make (Mytype)
也相关:()