title: Generic Stack implementation in haskell
body: <p>I am trying to create a generic implementations of stack operations. On compiling it gives an error:</p>
  
  <pre><code>Duplicate instance declarations:
        instance Show a =&gt; Show (Stack a) -- Defined at stackOp.hs:2:29
        instance Show a =&gt; Show (Stack a) -- Defined at stackOp.hs:11:10
  </code></pre>
  
  <p>Here is my code:</p>
  
  <pre><code>data Stack a = Stack [a]
                 deriving (Eq,Show,Ord)
  
  printelems :: (Show a) =&gt; [a] -&gt; String
  printelems [] = ""
  printelems x = show x
  printelems (x:xs) = show x ++ "-&gt;" ++ (printelems xs)
  
  
  
  instance (Show a) =&gt; Show (Stack a)
   where
   show (Stack l) = printelems l
  
  empty :: Stack a
  empty = []
  
  push :: a -&gt; Stack a -&gt; Stack a
  push x s = x:s
  </code></pre>