[Haskell-cafe] Very simple parser

Hugh Perkins hughperkins at gmail.com
Mon Jul 2 18:46:51 EDT 2007

Graham Hutton has some great tutorials on parsing.  Check out the "Are
parsers monodic?" thread (not exact name) for a good reference.

There's also a good tutorial at http://www.cs.nott.ac.uk/~gmh/book.html In
Section "Slides", click on "8 Functional parsers", but you may just want to
start from 1.  They're really quick and painless.

Graham Hutton's tutorials are about the only tutorials on monads that make
sense to me.  YMMV of course.

Other than that... a list is an instance of State, I think (?), so you can
do something like (writing this in directly, without trying to compile):

processor :: State a
processor = do value <- gets head
                       case value of
                            "blah" -> return blah
                            "foo" -> return foo

dotest = evalState( processor )["blah","foo"]

Note that I'm a total newbie, and I didnt check this compiles (almost
certainly doesnt) so take this with a wodge of salt

I cant say I really like the way I have a case that selects on strings to
decide which function to call.  If someone knows a more
elegant/spelling-safe way of doing this that'd be really useful generally.

For example something like this could be more spelling safe (if it worked)
(maybe it does???):

case value of
   (showConstr $ toConstr $ blah) -> return blah
   (showConstr $ toConstr $ foo) -> return foo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20070703/77830168/attachment.htm

More information about the Haskell-Cafe mailing list