[Haskell-cafe] [Haskell Cafe] Troubles with StateT and Parsec
psujkov at gmail.com
Mon Aug 3 18:42:12 EDT 2009
GHC 6.10.1, Parsec 3.0.0 and type signatures are right from the code: they
are actually real (except the ones with the <shortcuts>). I see now that it
is really a better idea to use internal Parser state to collect the data I
need to carry through, so in any case thank you
I've sent two letters on topic not to the mail-list, so I'll quote them
"to make the problem clear: I've changed parseSyslog function from Parser
type to StateT Parser type (a parser with some additional user state); the
question is: how should I use "parse" function, which expects Parser type
signature for it's first argument? Am I right that I should lift parse
function to the StateT transformer to achieve this?"
"the Parser datatype from the Parsec library is itself a State monad;
however, it's internal state is used for parsing purposes. What is a good
practice to implement stateful parsers with Parsec? Using StateT transformer
on top of the Parser type, or using it's own internal state? Or maybe there
is some better way, that I am anaware of?"
that's the state of things right now actually, but I think the solution is
already clear. Thanks to everyone in the conversation :)
2009/8/3 Bryan O'Sullivan <bos at serpentine.com>
> On Mon, Aug 3, 2009 at 10:46 AM, Paul Sujkov <psujkov at gmail.com> wrote:
>> parseSyslog :: StateT Integer Parser TimeStamp
>> parseString :: StateT Integer Parser LogString
>> and the following code:
>> parseString = do [...]
> Without real code to look at, it's impossible to properly debug the errors
> in your pseudocode above. For instance, your type signatures aren't real,
> and you don't mention which version of Parsec you're using.
> Regardless, you shouldn't need to use monad transformers with Parsec, as it
> has its own support for managing state that gives you exactly the same
> features as StateT. See the getState, setState, and updateState functions. I
> notice that you try to explain why you are using StateT later in your
> message, but I don't understand your description.
Regards, Paul Sujkov
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe