A valuable new combinator for Parsec?

Hello all, While using the very nice "option" combinator of Parsec recently, it seemed to me that it would be useful to have a more specific kind of combinator for optional tokens that wraps the token into a Maybe type. So, that gives: pmaybe :: GenParser tok st a -> GenParser tok st (Maybe a) pmaybe p = option Nothing (p >>= return . Just) I've been using it happily with some code of mine. Do people think that it would be generally useful to have in Parsec? Cheers, Maxime

On Mon, Mar 12, 2007 at 11:24:48AM +0100, Maxime Henrion wrote:
While using the very nice "option" combinator of Parsec recently, it seemed to me that it would be useful to have a more specific kind of combinator for optional tokens that wraps the token into a Maybe type.
So, that gives:
pmaybe :: GenParser tok st a -> GenParser tok st (Maybe a) pmaybe p = option Nothing (p >>= return . Just)
I've been using it happily with some code of mine. Do people think that it would be generally useful to have in Parsec?
Yes, it would certainly be useful. I think "optional" should work this way, but unfortunately it returns (). Pozdrawiam Tomek

At Mon, 12 Mar 2007 11:24:48 +0100, Maxime Henrion wrote:
pmaybe :: GenParser tok st a -> GenParser tok st (Maybe a) pmaybe p = option Nothing (p >>= return . Just)
I've been using it happily with some code of mine. Do people think that it would be generally useful to have in Parsec?
I believe I have written that same combinator a few times myself, so I vote yes. j.
participants (3)
-
Jeremy Shaw
-
Maxime Henrion
-
Tomasz Zielonka