From 4a5d01677ae457425336bf7de6ddffadf09bae83 Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Sun, 11 May 2014 22:07:09 +1000 Subject: Function to find all named nodes in a grasp program --- src/Grasp/Types.hs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src') diff --git a/src/Grasp/Types.hs b/src/Grasp/Types.hs index 72f835a..af43d51 100644 --- a/src/Grasp/Types.hs +++ b/src/Grasp/Types.hs @@ -1,6 +1,7 @@ module Grasp.Types ( GraspProgram(..), + namedNodes, nodesWithName, normalise, iso @@ -28,6 +29,18 @@ instance (Ord a, Ord b) => Eq (Gr a b) where +namedNodes :: GraspProgram -> [LNode String] +namedNodes g = + let nodes = Graph.labNodes g + edges = Graph.labEdges g + + nameEdges = filter (\(_,_,z) -> z == "name") edges + nameNodes = map (\(x,_,_) -> x) nameEdges + + in filter (\(x,_) -> x `elem` nameNodes) nodes + + + nodesWithName :: GraspProgram -> String -> [LNode String] nodesWithName g s = let nodes = Graph.labNodes g -- cgit