运行fold (+) 0 sample会给我一个关于 (+) 应用于太多参数的错误。为什么?
data(Ord a, Show a, Read a) => BST a = Void | Node {
val :: a,
left, right :: BST a
} deriving (Eq, Ord, Read, Show)
sample = Node 5 (Node 3 Void Void) (Node 10 Void Void)
fold :: (Read a, Show a, Ord a) => (a -> b -> b -> b) -> b -> BST a -> b
fold _ z Void = z
fold f z (Node x l r) = f x (fold f z l) (fold f z r)
Occurs check: cannot construct the infinite type: a = a -> a Probable cause: `+' is applied to too many arguments In the first argument of `fold'', namely `(+)' In the expression: fold' (+) 0 sample
参见:折叠