On 2004-09-29, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > You can use state monad to mimic mutation.
Is that really what I want? In other words, is there a completely different, more Haskellish, way to look at this?
> Also, take a look at the recursive decent monadic parsec library. It may > have done what you are trying to do.
Thanks for the pointer. I'll take a look.
Sometimes what you want really *is* a mutable value of some kind, but far less than you might expect.
I recently implemented an RDF/XML parser using Parsec to parse from an "event stream" of XMLish things. Parsec is Monadic, and provides for user state in the parser, which I duly used. But the amount of user state I used was tiny:
[[ data RDFParserState = RDFParserState { nodegen :: Int , listgen :: Int } ]]
I.e., just two counters that were used for generating identifiers within the parsing process. Everything else was quite comfortably treated as immutable values.
The code can be seen at:
http://www.ninebynine.org/Software/HaskellRDF/RDF/Harp/RDFXMLParser.hs
The function that invokes Parsec being 'parseEventsToRDF'. (This may not be the best introductory example, because it touches a lot of other logic. There is a test suite in the same directory if you want to dig deeper.)
#g
------------ Graham Klyne For email: http://www.ninebynine.org/#Contact
_______________________________________________ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe