I figured out how to do it: you just need to create a new graph with mkGraph
using the same list of nodes (but with the appropriate one modified, of course) and edges.
How to modify node label in fgl package?
题
I'm trying to modify the node label of an existing node within a graph that has been constructed using the fgl
Haskell package, but I'm unable to understand how to do that. I tried using insNode
to reinsert a new node with the same internal node ID and the new label, but I only get a Node Exception
when doing that.
MWE:
import Data.Graph.Inductive
import Data.Graph.Inductive.Example
main =
do let test = insNode (1, 'b') a
putStrLn $ show a
putStrLn $ show test
解决方案 2
其他提示
This one is more elegant and efficient:
updateLabel g n updateFun = case match n g of
(Just (p, _, l, s), cg) -> (p, n, updateFun l, s) & cg
(Nothing, _) -> error "not existent node!?"
Or if you are not sure if g - the graph - contains n - the node, go with:
updateLabel g n updateFun = case match n g of
(Just (p, _, l, s), cg) -> Just $ (p, n, updateFun l, s) & cg
(Nothing, _) -> Nothing
不隶属于 StackOverflow