summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Grasp/IP.hs20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/Grasp/IP.hs b/src/Grasp/IP.hs
index efb904d..6a4d452 100644
--- a/src/Grasp/IP.hs
+++ b/src/Grasp/IP.hs
@@ -2,10 +2,11 @@ module Grasp.IP (
IP,
singleton,
+ empty,
+ isEmpty,
peek,
push,
- pop,
- isEmpty
+ pop
) where
@@ -25,15 +26,18 @@ newtype IP = IP [GNode]
singleton :: GNode -> IP
singleton n = IP [n]
-peek :: IP -> GNode
-peek (IP p) = head p
+empty :: IP
+empty = IP []
+
+isEmpty :: IP -> Bool
+isEmpty (IP p) = (length p == 0)
+
+peek :: IP -> Maybe GNode
+peek (IP p) = if (length p == 0) then Nothing else Just (head p)
push :: GNode -> IP -> IP
push n (IP p) = IP (n:p)
pop :: IP -> IP
-pop (IP p) = IP (tail p)
-
-isEmpty :: IP -> Bool
-isEmpty (IP p) = (length p == 0)
+pop (IP p) = if (length p == 0) then IP p else IP (tail p)