title: Pop not working properly, stack is always empty
body: <p>I've been trying to implement a Stack machine in Haskell for a college work but I'm having a hard time. When I try to push a value into a stack, it always returns only the value I just pushed.</p>
  <pre><code>module Stack(Stack, push, pop, top, stackEmpty, newStack) where
  push :: t -&gt; Stack t -&gt; Stack t
  pop :: Stack t -&gt; Stack t
  top :: Stack t -&gt; t
  stackEmpty :: Stack t -&gt; Bool
  
  
  newStack   :: Stack t
  data Stack t = Stk [t]
  
  newStack = Stk []
  
  push x (Stk xs) = (Stk (x : xs))
  
                      
  pop (Stk [])      = error &quot;retirada em pilha vazia&quot;
  pop (Stk (_ : xs)) = Stk xs
  top (Stk [])     = error &quot;topo de pilha vazia&quot;
  top (Stk (x : _)) = x
  
  stackEmpty (Stk []) = True
  stackEmpty _         = False
  
  
  instance (Show t) =&gt; Show (Stack t) where
      show (Stk []) = &quot;#&quot;
      show (Stk (x : xs)) = (show x) ++ &quot;|&quot; ++ (show (Stk xs))
  </code></pre>
  <p>This is what happens if I try to push every time in the same stack, it keeps pushing the value to an empty list. I guess that happens because I declared <code>pilha</code> as a <code>newStack</code> and a <code>newStack</code> is an empty list, so every time I push to it it pushes to an empty list, right? The problem is I don't know how to save the value of the stack.</p>
  <pre><code>ghci&gt; let pilha = newStack 
  ghci&gt; push 5 pilha 
  5|#
  ghci&gt; push 6 pilha
  6|#
  ghci&gt;
  </code></pre>
  <p>This is what I did for it to work in the terminal</p>
  <pre><code>ghci&gt; let oldStack = push 5 newStack 
  ghci&gt; show oldStack
  &quot;5|#&quot; 
  ghci&gt; let newerStack = push 6 oldStack
  ghci&gt; show newerStack
  &quot;6|5|#&quot;
  ghci&gt; newerStack = push 7 newerStack 
  ghci&gt; show newerStack
  &quot; 
  </code></pre>
  <p>I know that that's the logic, every time I push I need to create a new <code>Stack</code> that will use the values from the old stack, but I can't seem to figure it out how to code it.</p>