]> gitweb @ CieloNegro.org - hs-rrdtool.git/blob - Types/Data/Graph/RootPath.hs
working on graphs...
[hs-rrdtool.git] / Types / Data / Graph / RootPath.hs
1 {-# LANGUAGE
2   EmptyDataDecls,
3   TypeFamilies,
4   UndecidableInstances
5   #-}
6 module Types.Data.Graph.RootPath
7     ( GetLPath
8     , GetDistance
9     , GetLPathNodes
10     )
11     where
12
13 import qualified Types.Data.List     as L
14 import qualified Types.Data.List.Ops as L
15
16 import Types.Data.Bool
17 import Types.Data.Graph
18 import Types.Data.Ord
19
20 -- NodeID
21 type family   NodeID lNode
22 type instance NodeID (LNode nodeID nodeLabel) = nodeID
23
24 -- NodeIDA
25 data NodeIDA
26 type instance L.App NodeIDA lNode = NodeID lNode
27
28 -- NodeLabel
29 type family   NodeLabel lNode
30 type instance NodeLabel (LNode nodeID nodeLabel) = nodeLabel
31
32 -- FindP
33 type family   FindP node lPaths
34 type instance FindP n L.Null                     = L.Null
35 type instance FindP n (L.Cons (LPath L.Null) ps) = FindP n ps
36 type instance FindP n (L.Cons (LPath (L.Cons (LNode n' l) ns)) ps)
37     = If (n :==: n')
38          (L.Cons (LNode n' l) ns)
39          (FindP n ps)
40
41 -- GetLPath
42 type GetLPath node lPaths
43     = LPath (GetLPath' node lPaths)
44
45 -- GetLPath'
46 type GetLPath' node lPaths
47     = L.Reverse (FindP node lPaths)
48
49 -- GetDistance
50 type GetDistance node lPaths
51     = NodeLabel (L.Head (FindP node lPaths))
52
53 -- GetLPathNodes
54 type GetLPathNodes node lPaths
55     = L.Map NodeIDA (GetLPath' node lPaths)