我有一个数据类型:
datatype 'a tree = LEAF of 'a
| NODE of 'a tree * 'a tree;
我希望创建一个名为 maptree(f) 的函数,它返回一个匿名函数,该函数能够在树上按元素执行 f。为什么以下不起作用?
fun maptree(f) = fn LEAF(a) => LEAF(f(a))
| NODE((b,c)) => NODE(f(b), f(c));
我得到错误:
stdIn:56.7-56.65 Error: types of rules don't agree [circularity]
earlier rule(s): 'Z tree tree -> 'Y tree tree
this rule: 'Z tree -> 'Y tree
in rule:
NODE (b,c) => NODE (f b,f c)