Hi haskellers,<br><br>I have a few problems using monad transformers. I have such two functions:<br><br>parseSyslog :: StateT Integer Parser TimeStamp<br>parseString :: StateT Integer Parser LogString<br><br>and the following code:<br>
parseString = do<br> -- string parse here, all in the form of lift $ <parser><br> stamp <- lift $ lexeme parseTimestamp -- <?> "timestamp"<br> message <- lift $ manyTill anyToken eof -- <?> "message"<br>
return (LogString <...parsed values here...> (check stamp console message) <...more parsed values here...>)<br> where check :: (Maybe TimeStamp) -> Console -> String -> Maybe TimeStamp<br> check Nothing Syslog message = case (lift parse $ parseSyslog "" message) of<br>
Left err -> Nothing<br> Right res -> Just res<br> <...other clauses here...><br><br>this code seems quite intuitive to me, however it doesn't compile with a king error:<br>
<br> Couldn't match kind `(* -> *) -> * -> *' against `?? -> ? -> *'<br> When matching the kinds of `t :: (* -> *) -> * -> *' and<br> `(->) :: ?? -> ? -> *'<br>
Probable cause: `lift' is applied to too many arguments<br> In the first argument of `($)', namely `lift parse'<br><br>I'm not so familiar with monad transformers whatsoever, so I'll be very happy if someone can show me the right way. The code compile nicely if I use "parse" line in a such way:<br>
<br>check Nothing Syslog message = case (parse (evalStateT parseSyslog 0) "" message) of<br><br>but this is not what I really want. To be accurate, here is the sequence which I do want to have in the code:<br><br>
some user state is initialized; parseString gets called many times and changes the state via call to the parseSyslog (that is the only function that really uses/affects user state, everything else is pure Parsec code with it's own internal state). Two main problems that I have now is:<br>
<br>1) impossibility to use parse/parseTest functions with the (StateT <state type> Parser <parse type>) argument. I want it to be lifted somehow, but cannot see how<br>2) too many lifts in the code. I have only one function that really affects state, but code is filled with lifts from StateT to underlying Parser<br>
<br>Sorry if the questions are silly; any help is appreciated<br><br>-- <br>Regards, Paul Sujkov<br>