KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm surprised that I could not find any info on this. I must be the only person having any trouble with it. So, let's say I have a dash counter. I want it to count the number of dashes in the string, and return the string. Pretend I gave an example that won't work using parsec's state handling. So this should work: dashCounter = do str <- many1 dash count <- get return (count,str) dash = do char '-' modify (+1) And indeed, this compiles. Okay, so I try to use it: :t parse dashCounter "" "----" parse dashCounter "" "----" :: (Control.Monad.State.Class.MonadState t Data.Functor.Identity.Identity, Num t) => Either ParseError (t, [Char]) Okay, that makes sense. It should return the state and the string. Cool. >parse dashCounter "" "----" <interactive>:1:7: No instance for (Control.Monad.State.Class.MonadState t0 Data.Functor.Identity.Identity) arising from a use of `dashCounter' Possible fix: add an instance declaration for (Control.Monad.State.Class.MonadState t0 Data.Functor.Identity.Identity) In the first argument of `parse', namely `dashCounter' In the expression: parse dashCounter "" "----" In an equation for `it': it = parse dashCounter "" "----" Oops. But then how could it have ever hoped to work in the first place? There's no way to input the initial state. There is also a function: >runPT dashCounter (0::Int) "" "----" But it gives a similar error. <interactive>:1:7: No instance for (Control.Monad.State.Class.MonadState Int m0) arising from a use of `dashCounter' Possible fix: add an instance declaration for (Control.Monad.State.Class.MonadState Int m0) In the first argument of `runPT', namely `dashCounter' In the expressio
Tags (comma-separated)
Save Edits
Cancel