diff options
Diffstat (limited to 'src/Grasp/Types/IP.hs')
-rw-r--r-- | src/Grasp/Types/IP.hs | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/Grasp/Types/IP.hs b/src/Grasp/Types/IP.hs new file mode 100644 index 0000000..c7d3e4b --- /dev/null +++ b/src/Grasp/Types/IP.hs @@ -0,0 +1,47 @@ +module Grasp.Types.IP ( + IP, + + singleton, + empty, + isEmpty, + peek, + push, + pop, + shift + ) where + + + + +import Grasp.Types.GNode( GNode ) + + + + +newtype IP = IP [GNode] + deriving (Eq, Show) + + + + +singleton :: GNode -> IP +singleton n = IP [n] + +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) = if (length p == 0) then empty else IP (tail p) + +shift :: GNode -> IP -> IP +shift n (IP p) = if (length p == 0) then empty else IP (n:(tail p)) + |