[Haskell-beginners] Writing a custom pop function for a stack data type

divyanshu ranjan idivyanshu.ranjan at gmail.com
Tue Mar 12 11:53:43 CET 2013

You have declared new data type mystack not Stack, so haskell compiler
could not find Stack data type and its constructors. Secondly data type in
Haskell need to be start with capital letters like

data Mystack = Empty | Elem Char Mystack deriving Show
then correct Function definition is
pophead :: Mystack -> Char


On Tue, Mar 12, 2013 at 4:12 PM, doaltan <doaltan at yahoo.co.uk> wrote:

> Hi I have such a stack data structure:
> data mystack = Empty | Elem Char mystack deriving Show
> I'm trying to get the head of the stack using this:
> pophead :: Stack -> Char
> pophead Empty = Empty
> pophead (Element x stack) = x
> And I'm getting this error for the last sentence of the function :
> Not in
>  scope: data constructor `Stack'
> Can you tell me how to fix it?
> Thanks.
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20130312/5f1c9cbd/attachment.htm>

More information about the Beginners mailing list