Iteratee and parsec (was: Re: [Haskell-cafe] Re: Haskell-Cafe Digest, Vol 78, Issue 14)

Maciej Piechotka uzytkownik2 at gmail.com
Thu Feb 11 14:50:51 EST 2010


On Thu, 2010-02-11 at 13:34 -0600, Antoine Latter wrote:
> On Thu, Feb 11, 2010 at 1:27 PM, Maciej Piechotka
> <uzytkownik2 at gmail.com> wrote:
> > On Thu, 2010-02-11 at 11:00 -0500, Gregory Collins wrote:
> >> Maciej Piechotka <uzytkownik2 at gmail.com> writes:
> >>
> >> > On Tue, 2010-02-09 at 16:41 +0000, John Lato wrote:
> >> >>
> >> >> See http://inmachina.net/~jwlato/haskell/ParsecIteratee.hs for a
> valid
> >> >> Stream instance using iteratee.  Also Gregory Collins recently
> posted
> >> >> an iteratee wrapper for Attoparsec to haskell-cafe.  To my
> knowledge
> >> >> these are not yet in any packages, but hackage is vast.
> >> >
> >> > Hmm. Am I correct that his implementation caches everything?
> >>
> >> The one that John posted (iteratees on top of parsec) has to keep a
> copy
> >> of the entire input, because parsec wants to be able to do
> arbitrary
> >> backtracking on the stream.
> >>
> >
> > Well. Not quite. AFAIU (and ByteString implementation indicate so)
> the
> > uncons have a type
> >    uncons :: s -> m (Maybe (t, s))
> >
> > Where s indicates the position on the stream. Since it is impossible
> to
> > get back from having s alone the GC should be free to finalize all
> > memory allocated to cache the stream before the first living s.
> >
> 
> I'm not sure that this is correct -  parsec believes that it is free
> to call 'uncons' multiple times on the same value and receive an
> equivalent answer. 


That's what I meant. But it have to keep the reference to the first
element.

Consider example with list:



text = 'L':'o':'r':'e':'m':' ':'i':'p':'s':'u':'m':[]
                    ^               ^              ^
                    s1              s2             s3

uncons s1 == Identity (Just ('e', 'm':' ':'i':'p':'s':'u':'m':[]))
uncons s2 == Identity (Just ('p', 's':'u':'m':[]))
uncons s3 == Identity Nothing

However we will never get (nor we keep reference to):
'L':'o':'r':'e':'m':' ':'i':'p':'s':'u':'m':[],
'o':'r':'e':'m':' ':'i':'p':'s':'u':'m':[]
'r':'e':'m':' ':'i':'p':'s':'u':'m':[]
so those values can be freed as they are before first pointer (namely
s1).

Regards
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20100211/db621cd6/attachment.bin


More information about the Haskell-Cafe mailing list