G'day all.

On Wed, Nov 20, 2002 at 08:25:46PM +0000, Jorge Adriano wrote:

> I think both versions can be very useful:
> findM          :: (Monad m) => (a -> m Bool) -> [a] -> m (Maybe a)
> findM'          :: (Monad m) => (a -> Bool) -> [m a] -> m (Maybe a)

I can also make a case for:

  findM'' :: (Monad m) => (a -> Bool) -> [m a] -> m a
  findM'' p [] = fail "findM'': not found"
  findM'' p (x:xs) = p x >>= \b -> if b then return x else findM'' p xs

This goes with the philosophy that library functions shouldn't just
return Maybe.

Somewhere, somehow, there is a most general version of findM to be
found. :-)

Cheers,
Andrew Bromage
_______________________________________________
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to