What&#39;s &quot;going on&quot; is that data structures in Haskell are immutable. Thus, when you call &quot;push&quot; on a stack, you get a new stack with the new element pushed onto it, and the original stack is left un-touched.<br>
<br><div class="gmail_quote">On Fri, Feb 5, 2010 at 10:56 AM, michael rice <span dir="ltr">&lt;<a href="mailto:nowgate@yahoo.com">nowgate@yahoo.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<table cellspacing="0" cellpadding="0" border="0"><tbody><tr><td valign="top" style="font:inherit">Not using Stack for anything, just trying to understand how things can be done in Haskell.<br><br>To that end...<br><br>What&#39;s going on here? I&#39;m not even calling function POP.<br>
<br>Michael<br><br>======================<br><br>module Data.Stack (Stack, emptyStack, isEmptyStack, push, pop, top) where<br><br>newtype Stack a = Stack [a]<br><br>emptyStack = Stack []<br>isEmptyStack (Stack xs) = null xs<br>
push x (Stack xs) = Stack (x:xs)<br>pop (Stack (_:xs)) = Stack xs<br>top (Stack (x:_)) = x<br><br>======================<br><br>[michael@localhost ~]$ ghci Stack.hs<br>GHCi, version 6.10.4: <a href="http://www.haskell.org/ghc/" target="_blank">http://www.haskell.org/ghc/</a>  :? for help<br>
Loading package ghc-prim ... linking ... done.<br>Loading package integer ... linking ... done.<br>Loading package base ... linking ... done.<br>[1 of 1] Compiling Data.Stack       ( Stack.hs,
 interpreted )<br>Ok, modules loaded: Data.Stack.<br>*Data.Stack&gt; let s1 = emptyStack<br>*Data.Stack&gt; top (push 1 s1)<br>1<br>*Data.Stack&gt; top (push 2 s1)<br>2<br>*Data.Stack&gt; top (push 3 s1)<br>3<br>*Data.Stack&gt; let s2 = pop s1 <br>
*Data.Stack&gt; top s2<br>*** Exception: Stack.hs:8:0-28: Non-exhaustive patterns in function pop<br><br>*Data.Stack&gt; <br><br><br><br><br>--- On <b>Fri, 2/5/10, Casey Hawthorne <i>&lt;<a href="mailto:caseyh@istar.ca" target="_blank">caseyh@istar.ca</a>&gt;</i></b> wrote:<br>
<blockquote style="border-left:2px solid rgb(16, 16, 255);margin-left:5px;padding-left:5px"><br>From: Casey Hawthorne &lt;<a href="mailto:caseyh@istar.ca" target="_blank">caseyh@istar.ca</a>&gt;<br>Subject: Re: [Haskell-cafe] Stack ADT?<br>
To: <a href="mailto:haskell-cafe@haskell.org" target="_blank">haskell-cafe@haskell.org</a><br>Date: Friday, February 5, 2010, 10:36 AM<br><br><div>You could also implement stacks with mutable data structures, e.g.<br>STArray, etc.<br>
<br>What do you want to use a stack ADT for?<br><br>Usually stacks are discussed for pedagogical purposes but
 usually<br>recursion is used if you need a stack like operation.<br>--<br>Regards,<br>Casey<br>_______________________________________________<br>Haskell-Cafe mailing list<br><a href="http://mc/compose?to=Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br></div></blockquote></td></tr></tbody></table><br>

      <br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br>