ocaml中的模式匹配问题

发布于 2024-10-09 15:44:52 字数 940 浏览 4 评论 0原文

我编写了用于分解布尔函数的函数,问题是我得到的编译是:“警告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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

分开我的手 2024-10-16 15:44:52

分解 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 type unit -> unit (because you're returning fun () -> ...). 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 the fun () -> bit, so the unit argument isn't necessary.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文