我知道文件夹在Leaf上的工作方式,但是我不知道文件夹在Node上的工作方式。如果我们已经有f和z作为参数,则参数\ xz'是什么。假设我们有
tree = Node [Leaf 1, Leaf 2, Node [Leaf 1, Leaf 3]]
Run Code Online (Sandbox Code Playgroud)
该代码如何工作
foldr (+) 0 tree
Run Code Online (Sandbox Code Playgroud)
data RoseTree a = Leaf a | Node [RoseTree a]
instance Foldable RoseTree where
foldr f z (Leaf x) = f x z
foldr f z (Node ns) =
foldr (\x z' -> foldr f z' x) z ns
Run Code Online (Sandbox Code Playgroud) 为什么不能在Haskell中导入Data.Stream?
Prelude> import Data.Stream
<no location info>: error:
Could not find module ‘Data.Stream’
Perhaps you meant Data.String (from base-4.12.0.0)
Run Code Online (Sandbox Code Playgroud)