arrows

Wolfgang Jeltsch wolfgang@jeltsch.net
Sat, 7 Dec 2002 00:57:18 +0100


On Friday, 2002-11-29, 14:12, CET, Ashley Yakeley wrote:
> At 2002-06-29 14:43, Wolfgang Jeltsch wrote:
>=20
> > To simplify things a bit, let's take a simpler Parser type which does=
n't
> > use monad state transformers but simple state transformers instead. T=
his
> > makes the type ParserState simpler. You can think of a parser state a=
s an
> > infinite list of substate-token pairs now. The tokens denote the inpu=
t
> > stream. The substates may be used to encapsulate parser states of a
> > subordinate parsing process. When a token is read, the corresponding
> > token-substate pair is discarded.
>
> Sounds very complicated. Wouldn't a simple stream transformer work?
>
>   newtype MyParser baseMonad token output =3D
>    MkMyParser (baseMonad token -> baseMonad output);

Hello Ashley,

I cannot see how this relatively simple representation can be used to des=
cribe=20
certain parsers. If I would use Identity for baseMonad, I would have a ty=
pe=20
for simple parsers. MyParser Identity would essentially be token -> outpu=
t.=20
Which function of this type should be used to describe, for instance,
    (a) a parser reading no tokens and returning ()
    (b) a parser reading two tokens and returning the pair of these token=
s?

> [...]

> > (I don't allow finite lists here to make some things a bit easier an =
more
> > elegant. You can easily produce an infinite list from a finite one by
> > applying something like (++ repeat Nothing) . map Just to the finite
> > list.)
>
> Wouldn't it be easier to allow finite token lists and have reading past=
 the
> last token be the same as mzero?

I consider it better to use infinite lists in the core parser module. I'm=
 able=20
to provide the functionality, you suggest here, on top of this core modul=
e,=20
and, in fact, I do so (see Seaweed.Core.Parsing.Utilities.convertTokenLis=
t).=20
This approch has (maybe among others) these two advantages:
    1.
        baseMonad doesn't generally have to be an instance of MonadPlus.
    2.
        The core module can concentrate on the (rather difficult) core
        mechanisms and leave the job of returning mzero at the end of the
        stream to another module.

Wolfgang

P.S.: The Seaweed CVS repository can be examined via
    http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/seaweed/.