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 :(得分:0)
如果你只是在括号上加上括号(追加(求解t1 [])(求解t2 []))x :: y :: xs - > [X + .Y] @ L1 然后代码就可以了。