[Haskell-cafe] ansi2html - one program, several issues

Isaac Dupree isaacdupree at charter.net
Sun Jul 20 09:55:15 EDT 2008

Dan Doel wrote:
> On Sunday 20 July 2008, John Meacham wrote:
>> I do not believe that is the case, since the return type of runParser
>> "Either ParseError a" means that before you can extract the result of
>> the parse from the 'Right' branch, it must evaluate whether the result
>> is 'Left' or 'Right' meaning it needs to parse the whole input in order
>> to determine whether the parse was succesful.


> It doesn't stop it from parsing the entire file strictly. However, what it 
> does do is prevent the parser from backtracking out of arbitrary amounts of 
> lookahead. So, unless you use try (which allows for lookahead), when any 
> token is consumed by the parser, it can be garbage collected (assuming the 
> parser is the only thing pointing to the token stream). So, it consumes its 
> input strictly, but with limited overhead (ideally using try only for some 
> small bounded lookahead where it's needed).

So with Parsec, you can keep the *input* from filling up memory, but if 
you do, the *result* will still take up space (e.g. Right (value)).  For 
a simple transformation where the output is a similar string to the 
input, it will be just as large, so not much space is actually saved 
(maybe a factor of 2 -- just keeping the output, not also the input), it 


More information about the Haskell-Cafe mailing list