[Haskell-cafe] Parsec question: how to access parser state

Dimitry Golubovsky dimitry at golubovsky.org
Sun Mar 20 15:32:38 EST 2005


Hi,

I am trying to develop a parser with the Parsec library. At some point I 
need to do something with parser state, say, convert it to a string.

I declared the type for the parser:

type TParser a = GenParser Token (FiniteMap String Declaration) a

The FiniteMap (which is the user state) is expected to be updated during 
parsing whus building some internal lookup table.

and in one of the parsing functions I want to call

show getState

assuming it will apply show to the FiniteMap and return some string of 
characters.

During compliation, I get:

     No instance for (Show (GenParser tok st st))
       arising from use of `show' at (file location)
     In the first argument of `xxxx', namely `(show getState)'

But GenParser is a newtype, not a data constructor, so attempt to write

instance Show (GenParser tok st t)

results in error message about missing constructor GenParser.

How could I extract actual user state from the result of getState?

The parser itself works as needed, but dealing with user state gets me 
in trouble.

Dimitry Golubovsky
Middletown, CT



More information about the Haskell-Cafe mailing list