[Haskell-cafe] Parser problem continued

robert dockins robdockins at fastmail.fm
Tue Mar 15 10:39:11 EST 2005


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

't' is not in scope at the arrow.  t only exists inside the
do block, and your code parses like this

( do t <- .... return (t+e) ) +++ ( return t )

perhaps like this:

expr = do t <- term
           (do symbol "+"
               e <- expr
               return (t+e)
           )
           +++
           (return t)


although I think you may also want a 'try' before the first alternative.



More information about the Haskell-Cafe mailing list