【问题标题】:Problem with pattern matching in ocamlocaml中的模式匹配问题
【发布时间】:2011-05-31 18:45:51
【问题描述】:

我写了一个用于分解布尔函数的函数,问题是编译我得到这个:“警告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))   

【问题讨论】:

    标签: functional-programming pattern-matching ocaml


    【解决方案1】:

    decomposition state_init new_state state f1 的类型为 unit -> unit(因为您返回的是 fun () -> ...)。所以如果你只是这样称呼它,它不会做任何事情。

    您要么必须将其称为decomposition state_init new_state state f1 (),要么删除fun () -> 位,因此不需要单位参数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-11
      • 1970-01-01
      • 1970-01-01
      • 2022-08-06
      • 2011-03-03
      • 1970-01-01
      相关资源
      最近更新 更多