2014-11-02 52 views
-1
type exptree = Num of float | Add of exptree*exptree | Sub of exptree*exptree | Div of exptree*exptree | Mult of exptree*exptree | Sqrt of exptree| Sin of exptree | Log of exptree | Cos of exptree | Tan of exptree | Abs of exptree | Exp of exptree*exptree | Eexp of exptree;; 

let rec solve t l1 = match t with Num(x) -> x::l1 
    | Add(t1, t2) -> match (append (solve t1 []) (solve t2 [])) with x::y::xs -> [x+.y]@l1 
    | Mult (t1,t2) -> match (append (solve t1 []) (solve t2 [])) with x::y::xs -> [x*.y]@l1;; 

解決是給下面的錯誤:程序顯示錯誤

Characters 145-148: 
    | Add(t1, t2) -> match (append (solve t1 []) (solve t2 [])) with x::y::xs -> [x+.y]@l1;; 
     ^^^ 
Error: The variant type list has no constructor Add 

回答

0

,如果你只是把括號匹配時(追加(解決T1 [])(解決T2 [])),其中x: :y :: xs - > [x + .y] @ l1 然後代碼將工作。