OCaml Typechecking Problem With Functors and Polymorphic Variants
我在OCaml中使用函子时遇到问题。我有一个模块类型
1 2 3 4 5 6 7 8 9 | module type TASK = sig type task_information type task_information_as_lists type abstract_u_set_type module AbstractUSet : Set.S with type t = abstract_u_set_type val mk_task_information : task_information_as_lists -> task_information end |
类型为
这是模块类型
1 2 3 4 |
为了进行测试,我想拥有一个
因此我构建了
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | module StringTaskNode : TASK_NODE = struct type t = string let compare = compare let to_string s ="Node" ^ s end module StringInfoCarrier (TN : TASK_NODE) : (INFO_CARRIER with module INODE = TN) = struct module INODE = TN type u = [`V of TN.t list | `E of TN.t] list end module StringTask (TN : TASK_NODE) (IC : INFO_CARRIER with module INODE = TN) : (TASK with type task_information_as_lists := IC.u with type abstract_u_set_type := Set.Make(IC.INODE).t) = struct module N = IC.INODE module AbstractUSet = Set.Make(IC.INODE) type task_information = {v_nodes : AbstractUSet.t ; e_nodes : N.t} let mk_task_information info_list = match info_list with | (`V v)::(`E e)::[] -> {v_nodes = AbstractUSet.of_list v ; e_nodes = e;} | _ -> raise .... (* raising an error here *) end |
然后我有另一个模块
1 2 3 4 5 6 | module ProdFP (TN : TASK_NODE) (IC : INFO_CARRIER with module INODE=TN) (TA : TASK with type abstract_u_set_type:=u with type task_information_as_lists:=IC.u) = struct ... end |
到目前为止,没有错误发生。但是,当我将所有内容放在
1 2 3 4 5 6 |
这是测试模块:
1 2 3 4 5 6 7 8 9 10 11 12 | module Test = struct module STN = StringTaskNode module SIC = StringInfoCarrier(STN) module ST = StringTask(STN)(SIC) module PF = ProdFP(STN)(SIC)(ST) let v_list =["a";"b"] let e ="c" let info_as_list = [`V v_list ; `E e] let info = ST.mk_task_information info_as_list (* THIS IS WHERE THE ERROR HAPPENS *) end |
我知道,这是一篇很长的文章,但是我尝试添加尽可能多的信息。
如果您能帮助我,那就太好了:)
问题似乎仅仅是
1 2 3 | module StringTaskNode : TASK_NODE = struct ... end |
此约束使类型
1 2 3 | module StringTaskNode = struct ... end |
应解决此特定问题。