On Sun, Jan 17, 2010 at 6:30 AM, Mark Spezzano <mark.spezzano@chariot.net.au> wrote:
I've written a Parser called keyword
keyword :: Parser Verb
keyword = do x <- many1 letter
return (read x)
(read this as "take-at-least-one-alphabetic-letter-and-convert-to-a-Verb-type")
which DOES work provided that the user types in one of my Verbs. If they don't, well, the whole thing fails with an Exception and halts processing, returning to GHCi prompt.
Question: Am I going about this the right way? I want to put together lots of "data" types like Verb and Noun etc so that I can build a kind of "BNF grammar".
Question: If I am going about this the right way then what do I about the "read x" bit failing when the user stops typing in a recognised keyword. I could catch the exception, but typing an incorrect sentence is just a typo, not really appropriate for an exception, I shouldn't think. If it IS appropriate to do this in Haskell, then how do I catch this exception and continue processing.