arrows

Ashley Yakeley ashley@semantic.org
Fri, 29 Nov 2002 05:12:51 -0800


At 2002-06-29 14:43, Wolfgang Jeltsch wrote:

>To simplify things a bit, let's take a simpler Parser type which doesn't
>use monad state transformers but simple state transformers instead. This
>makes the type ParserState simpler. You can think of a parser state as
>an infinite list of substate-token pairs now. The tokens denote the
>input 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 = 
   MkMyParser (baseMonad token -> baseMonad output);

>    (>>=):    sequencing of parsers
>    return:   returning values
>    fail:     generation of always failing parsers
>    mzero:    always failing parser
>    mplus:    parsing using alternative parsers
>    fmap:     applying a function to the result of a parser
>    (>>>):    providing high-level tokens and parsing using these tokens
>    identity: reading a single token
>    pure:     reading a single token and applying a function to it

I think I can do all of those for MyParser. There's a one-token 
look-ahead variant:

  newtype MyLookaheadParser m t a = 
   MkMyLookaheadParser (m t -> Maybe t -> m (Maybe t,a));

>(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?

-- 
Ashley Yakeley, Seattle WA