0
我試圖運行一個函數subst(tr,v1,v2),它返回一個新的ntree,其中v1的所有值都被v2替換爲輸出樹。以ml爲單位的循環誤差
datatype 'a ntree = leaf of 'a | node of 'a ntree list;
fun map(f, []) = [] | map(f,x::t)=f(x) :: map(f,t);
fun subst(leaf(d), v1, v2) = if d=v1 then v2 else d
| subst(node(q), v1, v2) = let fun w(k) =
if k=v1 then subst(v2, v1, v2) else subst(k, v1, v2)
in map(w, q)
end;
但我得到一個循環錯誤b/c我的rhs of子句不同意w /函數結果類型。我的表達是「」 Z名單,我的結果類型是「」 Z
謝謝!它使用你的建議後: fun subst(leaf(t),v1:string,v2:string)= if t = v1 then leaf(v2)else leaf(t) | (節點(u),v1,v2)=節點(map(p,u)) end; – user2285163