Combinators for ReadP

Martin Sjögren msjogren at gmail.com
Mon Jul 26 07:17:51 EDT 2004


On Mon, 26 Jul 2004 11:00:31 +0100, Malcolm Wallace
<malcolm.wallace at cs.york.ac.uk> wrote:
> > While we're discussing changes, is there an overwhelmingly good reason
> > for the use of local quantification beyond making the type signatures
> > simpler? Writing
> >   newtype ReadP r a = R ((a -> P r) -> P r)
> > (like in ContT) would make ReadP completely Haskell98 as far as I can tell.
> 
> I think you'll find that without the local universal quantifier,
> you cannot make ReadP a (useful) instance of Monad, because your
> 'r' parameter would be fixed across >>=, whereas it really needs to
> be variable.

Uhh. But it works for ContT, so why not for ReadP? The only point time
you have to fix the r is when you want to "run" the parser, all other
parsers will be polymorphic in r:

parseFoo :: ReadP r Foo
parseBar :: ReadP r Bar

readP_to_S :: ReadP a a -> ReadS a

I do exactly this in the package description parsing code of Cabal
(using a locally hacked ReadP, Cabal really must be H98...), and it
works just fine.


/Martin


More information about the Libraries mailing list