Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- data NonemptyStack a
- newStack :: a -> NonemptyStack a
- push :: a -> NonemptyStack a -> NonemptyStack a
- pop :: NonemptyStack a -> (NonemptyStack a, Maybe a)
- top :: NonemptyStack a -> a
- stackToList :: NonemptyStack a -> [a]
Documentation
data NonemptyStack a Source #
A stack that always has at least one value on it.
Instances
Show a => Show (NonemptyStack a) Source # | |
Defined in Matterhorn.Types.NonemptyStack showsPrec :: Int -> NonemptyStack a -> ShowS # show :: NonemptyStack a -> String # showList :: [NonemptyStack a] -> ShowS # |
newStack :: a -> NonemptyStack a Source #
Make a new stack with the specified value at the bottom.
push :: a -> NonemptyStack a -> NonemptyStack a Source #
Push the specified value on to the stack.
pop :: NonemptyStack a -> (NonemptyStack a, Maybe a) Source #
Pop the top value from the stack. If a value could be popped,
return the new stack and the value that was popped. Otherwise return
the stack unmodified with Nothing
to indicate that nothing was
popped.
top :: NonemptyStack a -> a Source #
Return the value on the top of the stack. Always succeeds since the stack is guaranteed to be non-empty.
stackToList :: NonemptyStack a -> [a] Source #
Return the stack as a list, topmost element first.