[Haskell-cafe] Conversion between MonadPlus instances

Gracjan Polak gracjan at acchsh.com
Fri Jul 1 06:33:13 EDT 2005

Hi all,

A simple question for advanced Haskellers, but I still have some 
problems bending my mind over it.

Example: I have some function, that can return multiple results. 
Currently I need only the first one, but in the spirit of NotJustMaybe, 
I try to be as general as possible.

If I code it like this:

reduction :: (MonadPlus m) => [Rule] -> Expr -> m Expr
reduction expr = do
     rule <- rules
     reduction rule expr

Variable m gets unified with []. But I want m to stay as general as 
possible here.

This version works, but I somehow do not like the "smell" of it

reduction expr = do
     let listmonad = do
         rule <- rules
         reduction rule expr
     msum (map return listmonad)

Is there a better way how to "embed" MonadPlus in other "MonadPlus"?


More information about the Haskell-Cafe mailing list