make basic app demo slightly more interesting
Wed Nov 16 12:06:56 WET 2005 Malcolm.Wallace@cs.york.ac.uk
* make basic app demo slightly more interesting
Now that we can edit the info on an edge, let's make the simple
application demo slightly more interesting. The nodes now collect all
the numbers on their incoming edges into a list. Then the sum of the
numbers in a node is pushed out along its outgoing edges. If you keep
hitting the 'perform analysis' step, it will eventually reach a fixed
point.
{
hunk ./src/Main.hs 19
- (undefined::Int)
+ ([]::[Int])
hunk ./src/Main.hs 31
-instance Analysis () Int [Int] where
+instance Analysis () [Int] [Int] where
hunk ./src/Main.hs 33
- (g, nodemap, IntMap.map (\e-> push nodemap e) edgemap)
+ (g, IntMap.mapWithKey (\k v-> (edgemap `accumulateIn` k) v) nodemap
+ , IntMap.map (\e-> nodemap `pushAlongEdge` e) edgemap)
hunk ./src/Main.hs 36
- (g, nodemap, IntMap.map (setEdgeInfo []) edgemap)
+ (g, IntMap.map (setInfo blank) nodemap
+ , IntMap.map (setEdgeInfo blank) edgemap)
hunk ./src/Main.hs 39
-push :: IntMap (Node Int) -> Edge [Int] -> Edge [Int]
-push nodemap edge = setEdgeInfo (nub (n: getEdgeInfo edge)) edge
+-- Every edge is augmented with the sum of the numbers in its from-node.
+pushAlongEdge :: IntMap (Node [Int]) -> Edge [Int] -> Edge [Int]
+nodemap `pushAlongEdge` edge = setEdgeInfo (nub (sum n: getEdgeInfo edge)) edge
hunk ./src/Main.hs 44
+
+-- Every node is augmented with a list of all the numbers in its incoming edges.
+accumulateIn :: IntMap (Edge [Int]) -> NodeNr -> Node [Int] -> Node [Int]
+(edgemap `accumulateIn` nr) node = setInfo (nub (es++getInfo node)) node
+ where es = (concat . IntMap.elems
+ . IntMap.map getEdgeInfo
+ . IntMap.filter (\e-> getEdgeTo e == nr) )
+ edgemap
}