ocaml中的模式匹配问题
我编写了用于分解布尔函数的函数,问题是我得到的编译是:“警告5:此函数应用程序是部分的,也许缺少一些参数。” 我该如何解决这个问题?我设置了错误的模式匹配,或者无法使用模式匹配运行此操作
代码如下:
let rec decomposition state_init state prec formula =
match formula with
And form -> (fun () ->
let f1 = List.hd form in
let f2 = And(List.tl form )in
let new_state = Forms (state_init,f1) in
decomposition state_init new_state state f1;
decomposition state_init new_state state f2;
Hashtbl.add graph new_state (("",false,state :: []) , []) ;
let x = Hashtbl.find graph state in
let succ = state :: snd x in
let (desc,last,ptrs) = fst x in
Hashtbl.replace graph state ( ("And-node",last,ptrs) , succ))
I wrote the function used to decompose a Boolean function, the problem is that the compilation I get this : "Warning 5: this function application is partial, maybe some arguments are missing."
How can I solve this problem? I've set wrong the patter matching or I can not run this operation with pattern matching
The code is the following:
let rec decomposition state_init state prec formula =
match formula with
And form -> (fun () ->
let f1 = List.hd form in
let f2 = And(List.tl form )in
let new_state = Forms (state_init,f1) in
decomposition state_init new_state state f1;
decomposition state_init new_state state f2;
Hashtbl.add graph new_state (("",false,state :: []) , []) ;
let x = Hashtbl.find graph state in
let succ = state :: snd x in
let (desc,last,ptrs) = fst x in
Hashtbl.replace graph state ( ("And-node",last,ptrs) , succ))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
分解 state_init new_state state f1
的类型为unit -> unit
(因为您返回的是fun () -> ...
)。所以如果你只是这样调用它,它不会做任何事情。您要么必须将其称为“decomposition state_init new_state state f1 ()”,要么删除“fun () ->”位,因此单位参数不是必需的。
decomposition state_init new_state state f1
has typeunit -> unit
(because you're returningfun () -> ...
). So if you just call it like that, it won't do anything.You either have to call it as
decomposition state_init new_state state f1 ()
, or remove thefun () ->
bit, so the unit argument isn't necessary.