例如,我有以下代码:
data Tree = Branches (List Tree) | Node Int
sumTree : Tree -> Int
sumTree (Branches xs) = sum (map sumTree xs)
sumTree (Node x) = x
如果我希望它通过总体检查,则必须手动展开地图:
data Tree = Branches (List Tree) | Node Int
sumTree : Tree -> Int
sumTree (Branches xs) = sum' xs where
sum' [] = 0
sum' (x::xs) = sumTree x + sum' xs
sumTree (Node x) = x
如果我想避免在所有地方都使用assert_total,那么函数式编程就可以发挥很多功能。有什么方法可以解决此问题?