[Haskell-beginners] Help! Trapped in the IO Monad!

Erik de Castro Lopo mle+cl at mega-nerd.com
Wed Jan 28 22:46:50 EST 2009


Alexander Dunlap wrote:

> You might also look at Control.Monad.filterM. I often define a
> function "partitionM" which is like partition except it uses a monadic
> test, just like you have.

Just for completeness, my partitionM:

  partitionM :: (Monad m) => (a -> m Bool) -> [a] -> m ([a], [a])
  partitionM _ []     =  return ([], [])
  partitionM p (x:xs) =  do
      flg <- p x
      (ys, ns) <- partitionM p xs
      return (if flg then (x:ys, ns) else (ys, x:ns))

Cheers,
Erik
-- 
-----------------------------------------------------------------
Erik de Castro Lopo
-----------------------------------------------------------------
"Indeed, I am impressed that Google runs an 8,000 node Linux
cluster, 5 data centers, an extensive network, and a rapidly
evolving application all with a staff of 12."
  -- http://research.microsoft.com/~gray/papers/FAAMs_HPTS.doc


More information about the Beginners mailing list