[Haskell-cafe] Lazy read

Malcolm Wallace Malcolm.Wallace at cs.york.ac.uk
Thu Feb 16 18:28:08 EST 2006

Neil Mitchell <ndmitchell at gmail.com> writes:

> > Check out ReadP or parsec, they are far superior in general. I think
> > there was a suggestion of replacing Read with ReadP?
> The whole point is not about writing a parser, its about having a
> parser written for me with deriving Read - unfortunately their is no
> deriving LazyRead or deriving Parsec etc.

Well, DrIFT can derive my TextParser class (another proposal for a
replacement of Read in haskell-prime).  However, TextParser isn't lazy
in the way you would like.  It can detect failure early and commit to
it, but detecting success early, in order to commit to returning the
initial portion of the datastructure, is not so nice to express.

Essentially, rather than having an indication of success/failure in the
type system, using the Maybe or Either types, you are asking to return
the typed value itself, with no wrapper, but perhaps some hidden bottoms
buried inside.  One could certainly define such a parsing set-up, but
there are no standard ones I know of.  The attraction of lazy parsing
is obvious, but there is a cost in terms of safety.


More information about the Haskell-Cafe mailing list