<div dir="ltr"><div>Given a node N and an edge label L, I want to do things like "find N, and all of N's L-children, and all of their L-children ... and add up their values". Ideally the fold would not traverse the whole graph. (Note that in general, the subgraph induced by N and L-succession is not a tree.)</div><div><br></div><div>Writing the fold myself, I can only imagine a very inefficient solution -- I would find each of N's L-children first, collect them, then find each of theirs, etc.</div><div><br></div><div>In Data.Graph.Inductive.Basic, FGL provides a function called "gfold". This is its type signature:</div><div><br></div><div>-- | Directed graph fold.</div><div>gfold :: (Graph gr) =>   (Context a b -> [Node])    -- ^ direction of fold</div><div>        -> (Context a b -> c -> d)    -- ^ depth aggregation</div><div>        -> (Maybe d -> c -> c, c)      -- ^ breadth\/level aggregation</div><div>        -> [Node]</div><div>        -> gr a b</div><div>        -> c</div><div><br></div><div>Is it what I'm looking for? If so, how does it work?</div></div>