[Haskell-cafe] Re: Badly designed Parsec combinators?

Christian Maeder maeder at tzi.de
Thu Feb 16 08:15:41 EST 2006

Juan Carlos Arevalo Baeza wrote:
>   Another case where I encounter this is with the "when" function:
> myParser2 :: Bool -> Parser ()
> myParser2 all =
>        do  string "Hello"
>            when all $
>                do  string ", world"
>            string "!"

I made a function (did I miss one in the base package?)

ignore :: Monad m => m a -> m ()
ignore m = m >> return()

and write "ignore $ string "..." if necessary.

"when b m" is "if b then m else return()".
I don't think that the then- or else- branch of any if- expression 
schould be automatically casted to some matching type "m ()" (and I 
don't know what implications this would have to typing in general).

However "when b m" could be generalized by "if b then ignore m else 
return ()". (The same applies to "unless")

Cheers Christian

More information about the Haskell-Cafe mailing list