foldl :: (a -> b -> a) -> a -> [b] -> a
foldl step zero (x:xs) = foldl step (step zero x) xs
foldl _ zero [] = zero
我不太明白为什么 (a -> b -> a ) 返回a, (a -> b -> a) -> a -> [b] -> a返回a。我认为它应该是: (a -> b -> c ) -> a -> [b] -> c。有人可以根据下面的示例向我解释一下。谢谢!
foldl (+) 0 (1:2:3:[])
foldl (+) (0 + 1) (2:3:[])
foldl (+) ((0 + 1) + 2) (3:[])
foldl (+) (((0 + 1) + 2) + 3) ([])
foldl (+) (((0 + 1) + 2) + 3)