[Haskell-beginners] Consuming Rule Based Parsing

Karl Voelker ktvoelker at gmail.com
Sat Nov 17 04:04:45 CET 2012

On Fri, Nov 16, 2012 at 5:13 PM, Christopher Howard <
christopher.howard at frigidcode.com> wrote:

> Thank you for your help. Can you elaborate a little more on your
> explanation? So, would "a" be some data type representing the atoms of
> the grammar? Or some kind of recursive data type that could represent
> any kind of valid structure? Or...?

The type parameter "a" is the output of that particular parser. So, a
parser for an integer might have type String -> Integer, while a parser for
some complicated data type Foo would have type String -> Foo.

I'll wait until I'm clear on that point before asking about how I would
> combine parsers. (Presumably, two combined parsers would both have to
> have the same "a" type.)

Since the parsers in this scheme are just functions, there are endless ways
they could be combined, and the input and output types may or may not match.

Some combinators you will probably want:

andThen :: Parser a -> (a -> Parser b) -> Parser b
orElse :: Parser a -> Parser a -> Parser a

And you might also want:

succeedWith :: a -> Parser a

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20121116/3b4cdc80/attachment.htm>

More information about the Beginners mailing list