[Haskell-cafe] Re: Frisby grammars that have context

Isaac Dupree isaacdupree at charter.net
Wed May 30 09:24:03 EDT 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Robin Green wrote:
> On Tue, 29 May 2007 19:28:02 -0400
> Isaac Dupree <isaacdupree at charter.net> wrote:
>> Luckily, Haskell's laziness means that doing an extra "postprocessing
>> pass" doesn't necessarily yield two traversals requiring the whole
>> file to be stored in memory, nor worse hacks.  (For grammars that
>> aren't too wild / sequential)
> 
> But the suggested code fragment on the frisby homepage:
> 
>   -- parse complete file, returning 'Nothing' if parse fails
>   fmap Just (myParser <<- eof) // unit Nothing
> 
> does require one traversal of the file all by itself. Obviously, in
> order to know whether the file was fully parsed without error, you need
> to read in the whole file, before you can write out anything. Hence
> you end up with *some* representation of the whole file in memory. So,
> yes, it doesn't necessarily yield two traversals, but you need to be
> careful if you want to avoid two traversals.

Yes, then the choices are being failable (using something like "error",
or whatever happens if you don't wrap your parser as suggested)
or better yet, a careful lazy datatype like
data ListOutput a = Nil | Cons a (ListOutput a) | Error (ErrorInfo)

Isaac
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGXXryHgcxvIWYTTURAnEeAJ9PrQUQLxeoTuIhaG8GcHW5mN6T4QCeL6FT
KCQeF43ye/GzLka4zFUK66s=
=y7MZ
-----END PGP SIGNATURE-----


More information about the Haskell-Cafe mailing list