summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2014-11-24 02:07:13 +1100
committerJed Barber <jjbarber@y7mail.com>2014-11-24 02:07:13 +1100
commit7b8583d6494ffe6f8f78ac6b9f5927b5edd3959b (patch)
tree81d05fb413eb1a99d82006e18ff620379ee9edc0 /src
parent92e5783f59ae689cf8b2da6a6e68f6b1e48b405e (diff)
Updated to make proper use of newtypes
Diffstat (limited to 'src')
-rw-r--r--src/Grasp/IP.hs19
-rw-r--r--src/Grasp/Types.hs65
2 files changed, 34 insertions, 50 deletions
diff --git a/src/Grasp/IP.hs b/src/Grasp/IP.hs
index 7b70e21..efb904d 100644
--- a/src/Grasp/IP.hs
+++ b/src/Grasp/IP.hs
@@ -10,27 +10,30 @@ module Grasp.IP (
-import Grasp.Node( GNode )
-import qualified Grasp.Node as GN
+import Grasp.Types( GNode )
-type IP = [GNode]
+
+
+newtype IP = IP [GNode]
+ deriving (Eq, Show)
+
singleton :: GNode -> IP
-singleton = (:[])
+singleton n = IP [n]
peek :: IP -> GNode
-peek = head
+peek (IP p) = head p
push :: GNode -> IP -> IP
-push = (:)
+push n (IP p) = IP (n:p)
pop :: IP -> IP
-pop = tail
+pop (IP p) = IP (tail p)
isEmpty :: IP -> Bool
-isEmpty = (==[])
+isEmpty (IP p) = (length p == 0)
diff --git a/src/Grasp/Types.hs b/src/Grasp/Types.hs
index af43d51..860e5ef 100644
--- a/src/Grasp/Types.hs
+++ b/src/Grasp/Types.hs
@@ -1,67 +1,48 @@
module Grasp.Types (
- GraspProgram(..),
-
- namedNodes,
- nodesWithName,
- normalise,
- iso
+ Instruction,
+ EdgeLabel,
+ GNode,
+ GEdge
) where
-import Data.Graph.Inductive.Graph( Node, LNode, LEdge, (&) )
-import qualified Data.Graph.Inductive.Graph as Graph
-import Data.Graph.Inductive.Tree
-import Data.List
-import Data.Maybe
-import qualified Data.Map as Map
-
-
-
-
-type GraspProgram = Gr String String
-
-instance (Ord a, Ord b) => Eq (Gr a b) where
- a == b = ((sort . Graph.labNodes $ a) == (sort . Graph.labNodes $ b)) &&
- ((sort . Graph.labEdges $ a) == (sort . Graph.labEdges $ b))
+import Grasp.Graph( Node, LNode, LEdge )
-namedNodes :: GraspProgram -> [LNode String]
-namedNodes g =
- let nodes = Graph.labNodes g
- edges = Graph.labEdges g
+newtype Instruction = Instruction String
+ deriving (Eq, Show)
- nameEdges = filter (\(_,_,z) -> z == "name") edges
- nameNodes = map (\(x,_,_) -> x) nameEdges
+newtype EdgeLabel = EdgeLabel String
+ deriving (Eq, Show)
- in filter (\(x,_) -> x `elem` nameNodes) nodes
+newtype GNode = GNode (LNode Instruction)
+ deriving (Eq, Show)
+newtype GEdge = GEdge (LEdge EdgeLabel)
+ deriving (Eq, Show)
-nodesWithName :: GraspProgram -> String -> [LNode String]
-nodesWithName g s =
- let nodes = Graph.labNodes g
- edges = Graph.labEdges g
- nodeLabelMap = Map.fromList nodes
- nameEdges = filter (\(_,_,z) -> z == "name") edges
- specific = filter (\(_,y,_) -> fromJust (Map.lookup y nodeLabelMap) == s) nameEdges
- nameNodes = map (\(x,_,_) -> x) specific
+gnode :: GNode -> Node
+gnode (GNode a) = fst a
- in filter (\(x,_) -> x `elem` nameNodes) nodes
+gninst :: GNode -> Instruction
+gninst (GNode a) = snd a
--- to-do
-normalise :: GraspProgram -> GraspProgram
-normalise g = Graph.mkGraph [] []
+gefrom :: GEdge -> Node
+gefrom (GEdge (a,_,_)) = a
+geto :: GEdge -> Node
+geto (GEdge (_,b,_)) = b
-iso :: GraspProgram -> GraspProgram -> Bool
-iso a b = (normalise a) == (normalise b)
+gelabel :: GEdge -> EdgeLabel
+gelabel (GEdge (_,_,c)) = c