summaryrefslogtreecommitdiff
path: root/src/Grasp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Grasp')
-rw-r--r--src/Grasp/Edge.hs43
-rw-r--r--src/Grasp/IP.hs36
-rw-r--r--src/Grasp/Node.hs47
3 files changed, 126 insertions, 0 deletions
diff --git a/src/Grasp/Edge.hs b/src/Grasp/Edge.hs
new file mode 100644
index 0000000..f0e1cc3
--- /dev/null
+++ b/src/Grasp/Edge.hs
@@ -0,0 +1,43 @@
+module Grasp.Edge (
+ GEdge,
+ GEdgeType,
+
+ singleton,
+ fromStringList,
+ src,
+ dest,
+ lab
+ ) where
+
+
+
+import Data.Graph.Inductive.Graph( LEdge )
+import Data.Map( Map )
+import qualified Data.Map as Map
+
+
+
+type GEdge = LEdge String
+type GEdgeType = String
+
+
+
+singleton :: Int -> Int -> String -> GEdge
+singleton f t s = (f,t,s)
+
+fromStringList :: Map String Int -> [(String,String,String)] -> [GEdge]
+fromStringList m es =
+ let change x = case (Map.lookup x m) of
+ Just a -> a
+ Nothing -> error "Grasp.Edge.fromStringList: no value for key " ++ x
+ in map (\(x,y,z) -> (change x, change y, z)) es
+
+src :: GEdge -> Int
+src (x,_,_) = x
+
+dest :: GEdge -> Int
+dest (_,x,_) = x
+
+lab :: GEdge -> String
+lab (_,_,x) = x
+
diff --git a/src/Grasp/IP.hs b/src/Grasp/IP.hs
new file mode 100644
index 0000000..7b70e21
--- /dev/null
+++ b/src/Grasp/IP.hs
@@ -0,0 +1,36 @@
+module Grasp.IP (
+ IP,
+
+ singleton,
+ peek,
+ push,
+ pop,
+ isEmpty
+ ) where
+
+
+
+import Grasp.Node( GNode )
+import qualified Grasp.Node as GN
+
+
+
+type IP = [GNode]
+
+
+
+singleton :: GNode -> IP
+singleton = (:[])
+
+peek :: IP -> GNode
+peek = head
+
+push :: GNode -> IP -> IP
+push = (:)
+
+pop :: IP -> IP
+pop = tail
+
+isEmpty :: IP -> Bool
+isEmpty = (==[])
+
diff --git a/src/Grasp/Node.hs b/src/Grasp/Node.hs
new file mode 100644
index 0000000..ce84163
--- /dev/null
+++ b/src/Grasp/Node.hs
@@ -0,0 +1,47 @@
+module Grasp.Node (
+ GNode,
+ GNodeType,
+
+ singleton,
+ uSingleton,
+ fromStringList,
+ lab,
+ inst,
+ idNo
+ ) where
+
+
+
+import Data.Graph.Inductive.Graph( LNode )
+import Data.Map( Map )
+import qualified Data.Map as Map
+
+
+
+type GNode = LNode (Maybe String, String)
+type GNodeType = (Maybe String, String)
+
+
+
+singleton :: Int -> String -> String -> GNode
+singleton i m s = (i,(Just m,s))
+
+uSingleton :: Int -> String -> GNode
+uSingleton i s = (i,(Nothing,s))
+
+fromStringList :: Map String Int -> [(String,String)] -> [GNode]
+fromStringList m ns =
+ let change x = case (Map.lookup x m) of
+ Just a -> a
+ Nothing -> error "Grasp.Node.fromStringList: no value for key " ++ x
+ in map (\(x,y) -> (change x, (Just x, y))) ns
+
+lab :: GNode -> Maybe String
+lab (_,(x,_)) = x
+
+inst :: GNode -> String
+inst (_,(_,x)) = x
+
+idNo :: GNode -> Int
+idNo (x,(_,_)) = x
+