diff options
author | Jed Barber <jjbarber@y7mail.com> | 2014-11-30 12:00:18 +1100 |
---|---|---|
committer | Jed Barber <jjbarber@y7mail.com> | 2014-11-30 12:00:18 +1100 |
commit | a697cfd93204e408fb9ac8363e3379f5a12e172e (patch) | |
tree | 9f2b6cea3115666c1c6941da18cf2e0e30c783e0 /src | |
parent | 094aba932ef8e4686c133f78e09740a481b7b653 (diff) |
IP functions now more tolerant of error conditions
Diffstat (limited to 'src')
-rw-r--r-- | src/Grasp/IP.hs | 20 |
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) |