[Haskell-cafe] Parser question

Nicola Whitehead nicolaw at unak.is
Tue Mar 15 07:28:31 EST 2005

Hi folks,
I have a parser problem. I have a basic calculator program (Graham Hutton's from Nottingham) which contains the following code:
-- Define a parser to handle the input
expr :: Parser Int
expr = do t <- term
              do symbol "+"
                   e <- expr
                   return (t + e)
          +++ return t

term :: Parser Int
term = do f <- factor
               do symbol "*"
               e <- expr
               return (f * t)
          +++ return f

factor :: Parser Int
factor = do symbol "("
                e <- expr
                symbol ")"
                return e
            +++ natural

symbol and natural are defined elsewhere and work fine, but when I compile it I get the error
ERROR "C:/HUGS/Calculator.hs":66 - Undefined variable "t"    
I suspect I'm missing something obvious, but for the life of me I can't see it. Any suggestions?
(Trying to keep a couple of weeks ahead of her students)
Dr Nik Freydís Whitehead
University of Akureyri, Iceland
Having the moral high ground is good.
Having the moral high ground and an FGMP-15 is better.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org//pipermail/haskell-cafe/attachments/20050315/16f07d6d/attachment-0001.htm

More information about the Haskell-Cafe mailing list