[Haskell-cafe] Using IsString with attoparsec

Yitzchak Gale gale at sefer.org
Tue Jan 25 14:16:57 CET 2011

Using the IsString instance for Parser in attoparsec is really nice,
but unfortunately, you can't use it out of the box for the most common

One would like to be able to write parsers in this style:

"(" *> stuff <* ")"

But the types of *> and <* are too general - there is no way for
the type checker to figure out which instance of IsString to use
for the discarded parameter.

I suggest adding the following type-specialized variants to

(<*.) :: Applicative f => f a -> f ByteString -> f a
(<*.) = (<*)

(.*>) :: Applicative f => f ByteString -> f a -> f a
(.*>) = (*>)

Once attoparsec-text gets its IsString instance, I would
add the same thing to Data.Attoparsec.Text, with ByteString
replaced by Text.

I have been using those for both attoparsec and attoparsec-text,
and I find them extremely useful.


More information about the Haskell-Cafe mailing list