[Haskell-beginners] Stack implementation

Uneeb Adeel Agha uneeb.agha at gmail.com
Sat Sep 10 21:07:48 UTC 2016


Hi,
I'm very, very new to Haskell. I am trying to understand the following error,
but I'm having a hard time wrapping my head around the whole type system.

Stack
 
                  module Stack (Stack(..)) where    import Prelude hiding (head, tail)    class Stack s where        empty :: s a        isEmpty :: s a -> Bool        cons :: s a -> a -> s a        head :: s a -> a        tail :: s a -> s a    data ListStack a = LS [a] deriving (Show)    instance Stack ListStack where        empty = LS []        isEmpty (LS s) = null s        cons (LS s) x = LS(x:s)        head(LS(x:_)) = x        tail(LS(x:xs)) = LS xs
                

Not using Mixmax yet?
 


The problem is that when I load this code in the interpreter and write>emptyI
get the following error
<interactive>:108:1:    No instance for (Show (s0 a0)) arising from a use of
‘print’    The type variables ‘s0’, ‘a0’ are ambiguous
I mean when I write "LS []" it works just fine. But something is wrong with
empty.

Thanks,
Uneeb
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160910/3570674b/attachment-0001.html>


More information about the Beginners mailing list