[Haskell-cafe] parsec3 pre-release [attempt 2]

Philippa Cowderoy flippa at flippac.org
Sat Feb 2 21:59:46 EST 2008


On Sat, 2 Feb 2008, Antoine Latter wrote:

> To expand on this point, side-effect instances of Stream don't play
> nice with the backtracking in Text.Parsec.Prim.try:
> 
> > import Text.Parsec
> > import Text.Parsec.Prim
> > import System.IO
> > import Control.Monad
> 
> > type Parser a = (Stream s m Char) => ParsecT s u m a
> 
> This particular instance was suggested by Derek.
> 

<snip>

We've been kicking this around on IRC a little, it took me a moment to 
remember the problem. Basically the problem isn't parsec/try playing badly 
with the stream - it's the stream playing badly with parsec/try. You need 
to keep track of where in the file you are and either cache it in an IORef 
or use seek to jump about appropriately. At the moment, Derek's instance 
doesn't know where it is in the stream so Parsec's backtracking is 
invisible to the underlying monad. That caching is the source of the 
potential leak I mentioned to you, because Parsec doesn't currently tell 
the stream when it's committed up to a given point and anything preceding 
it can be dropped safely.

We'll tell the list a nice story about this over the coming week. For now, 
it's nearly 3am here and I should get to bed!

-- 
flippa at flippac.org

The task of the academic is not to scale great
intellectual mountains, but to flatten them.


More information about the Haskell-Cafe mailing list