I'm trying to run a function subst(tr, v1, v2) which returns a new ntree where all the values of v1 are replaced by v2 in the output tree.
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;
but i get a circularity error b/c my rhs of clause does not agree w/ the function result type. my expression is ''Z list and my result type is ''Z