[Haskell-cafe] Continuable and serializable parsers.

Edward Kmett ekmett at gmail.com
Sun Dec 27 08:16:57 EST 2009


On Fri, Dec 25, 2009 at 11:56 AM, Serguey Zefirov <sergueyz at gmail.com>wrote:

> A pair of problems:
> 1) How to write a parser that could be restarted? Like, it will be
> represented by a function that returns something along the lines
>
> data ParseStepResult input result =
>    Success (Maybe (input -> ParseStepResult input result)) (Maybe result)
>  | Failure
>

This is basically the approach taken by the Iteratees package.


> 2) How to write parser like one above that could be saved into database?
>
> data ParserCont input result = ...
>    deriving (Show, Read)
> data ParseStepResult input result =
>    Success (Maybe (ParserCont input result)) (Maybe result)
>  | Failure
>

Yes, you'll have to defunctionalize the continuation , since you can't
serialize an arbitrary function in Haskell.


> I could imagine that it is possible using parser generator like Happy.
>
> Is it possible to get right using parsing combinators library?
>

You won't find a built-in monadic parser combinator library that works this
way, because of the necessary defunctionalization and the requirement that
each action and intermediate result be serializable.

You could probably encode the defunctionalization of a specific parser and
build up a combinator set yourself, however.

-Edward Kmett


> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20091227/765b35e4/attachment.html


More information about the Haskell-Cafe mailing list