summaryrefslogtreecommitdiff
path: root/src/Grasp/Types/IP.hs
blob: 8f7a74fbcf9b2b9ce5c0e9e1cc0222177b46cd5b (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
48
49
50
51
52
module Grasp.Types.IP (
	IP,

    singleton,
    empty,
    isEmpty,
    peek,
    push,
    pop,
    shift,

    toList
	) where




import Grasp.Graph( Node )




newtype IP = IP [Node]
    deriving (Eq, Show)




singleton :: Node -> IP
singleton n = IP [n]

empty :: IP
empty = IP []

isEmpty :: IP -> Bool
isEmpty (IP p) = (length p == 0)

peek :: IP -> Maybe Node
peek (IP p) = if (length p == 0) then Nothing else Just (head p)

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 :: Node -> IP -> IP
shift n (IP p) = if (length p == 0) then empty else IP (n:(tail p))

toList :: IP -> [Node]
toList (IP p) = p