[Haskell-cafe] Badly designed Parsec combinators?

Tomasz Zielonka tomasz.zielonka at gmail.com
Sun Feb 12 08:56:04 EST 2006


On Sun, Feb 12, 2006 at 01:57:07PM +0100, Daniel Fischer wrote:
> Am Sonntag, 12. Februar 2006 04:23 schrieb Juan Carlos Arevalo Baeza:
> > optional :: GenParser tok st a -> GenParser tok st ()
> > optional p          = do{ p; return ()} <|> return ()
> >
> >    Now, this completely loses the result of the optional parser. Better
> > would be:
> >
> > optional :: GenParser tok st a -> GenParser tok st (Maybe a)
> > optional p          = do{ x <- p; return (Just x) } <|> return Nothing
> >
> 
> Your above parser would be
> 
> option Nothing (fmap Just p) -- or you might use liftM.
> 
> Both are easy enough. If you think the naming is unfortunate, I wouldn't 
> flatly contradict, but it's too late now, I believe.

They are easy, but writing "option Nothing (liftM Just p)" for the nth
time tends to be boring. I could write my own combinator, but all the
good names are already taken. I too wish optional returned (Maybe a)
and I wonder how many programs would be broken if it was changed now.

Best regards
Tomasz

-- 
I am searching for programmers who are good at least in
(Haskell || ML) && (Linux || FreeBSD || math)
for work in Warsaw, Poland


More information about the Haskell-Cafe mailing list