From 73c926bed24e4dabe8efc3acc9b2a892c680bacd Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Thu, 18 Dec 2014 10:15:29 +1100 Subject: IPs changed to be lists of Nodes instead of GNodes --- src/Grasp/Monad.hs | 14 +++++++++----- src/Grasp/Types/IP.hs | 14 +++++++------- 2 files changed, 16 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/Grasp/Monad.hs b/src/Grasp/Monad.hs index a79cb20..3a3bd4f 100644 --- a/src/Grasp/Monad.hs +++ b/src/Grasp/Monad.hs @@ -86,7 +86,7 @@ construct (ns,es) = do Monad.when (noMain ns es) (error "could not find grasp:main") let graph = Graph.mkGraph (map GN.toLNode ns) (map GE.toLEdge es) - ips = map IP.singleton (getNodesWithName ns es "grasp:main") + ips = map (IP.singleton . GN.toNode) (getNodesWithName ns es "grasp:main") handles = Map.empty State.put (graph, ips, handles) @@ -183,7 +183,7 @@ reachable :: Gr Instruction EdgeLabel -> [IP] -> [Node] reachable gr ips = let named = getNamedNodes (map GN.mk (Graph.labNodes gr)) (map GE.mk (Graph.labEdges gr)) ipNodes = concatMap IP.toList ips - start = (map GN.toNode) . List.nub $ named ++ ipNodes + start = List.nub $ (map GN.toNode named) ++ ipNodes in reach gr start [] @@ -258,7 +258,7 @@ updateIP = do nexts <- nodesOut (EL.mk "next") (Maybe.fromJust curNode) r <- liftIO (Random.getStdRandom (Random.randomR (0, length nexts - 1))) - let updated = if (length nexts == 0) then IP.empty else IP.shift (nexts !! r) (head ips) + let updated = if (length nexts == 0) then IP.empty else IP.shift (GN.toNode (nexts !! r)) (head ips) ips' = updated:(tail ips) State.put (gr, ips', fh) ) @@ -268,7 +268,7 @@ updateIP = do pushIP :: GNode -> GraspM () pushIP n = do (gr, ips, fh) <- State.get - let ips' = if (length ips == 0) then [] else (IP.push n (head ips)):(tail ips) + let ips' = if (length ips == 0) then [] else (IP.push (GN.toNode n) (head ips)):(tail ips) State.put (gr, ips', fh) @@ -284,7 +284,11 @@ popIP = do peekIP :: GraspM (Maybe GNode) peekIP = do (gr, ips, fh) <- State.get - if (length ips == 0) then return Nothing else return (IP.peek (head ips)) + if (length ips == 0) then return Nothing + else return (do + node <- IP.peek (head ips) + label <- Graph.lab gr node + return (GN.mk (node, label)) ) diff --git a/src/Grasp/Types/IP.hs b/src/Grasp/Types/IP.hs index a548cc3..8f7a74f 100644 --- a/src/Grasp/Types/IP.hs +++ b/src/Grasp/Types/IP.hs @@ -15,18 +15,18 @@ module Grasp.Types.IP ( -import Grasp.Types.GNode( GNode ) +import Grasp.Graph( Node ) -newtype IP = IP [GNode] +newtype IP = IP [Node] deriving (Eq, Show) -singleton :: GNode -> IP +singleton :: Node -> IP singleton n = IP [n] empty :: IP @@ -35,18 +35,18 @@ empty = IP [] isEmpty :: IP -> Bool isEmpty (IP p) = (length p == 0) -peek :: IP -> Maybe GNode +peek :: IP -> Maybe Node peek (IP p) = if (length p == 0) then Nothing else Just (head p) -push :: GNode -> IP -> IP +push :: Node -> IP -> IP push n (IP p) = IP (n:p) pop :: IP -> IP pop (IP p) = if (length p == 0) then empty else IP (tail p) -shift :: GNode -> IP -> IP +shift :: Node -> IP -> IP shift n (IP p) = if (length p == 0) then empty else IP (n:(tail p)) -toList :: IP -> [GNode] +toList :: IP -> [Node] toList (IP p) = p -- cgit