summaryrefslogtreecommitdiff
path: root/src/Grasp/Node.hs
blob: ce84163a4e93378df8158f1c74f5b5d082e94ec7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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