在我的项目的其他地方,我已经定义了一个walk遍历AST 的函数,该函数的核心用于foldl将访问树中每个节点的结果减少为单个幺半群结果(例如,从特殊结果生成"符号表")树中的节点).
我的问题是:是否可以将这两种方法结合起来并使用像我的函数这样的walk函数:
walk :: Monoid a => (Node -> a) -> a -> Node -> a
walk f acc n = foldl (walk f) (acc <> f n) children
where
children = case n of
Blockquote b -> b
DocBlock d -> d
FunctionDeclaration {} -> functionBody n
List l -> l
ListItem i -> i …Run Code Online (Sandbox Code Playgroud)