.

1
2
3
4
5
6
7
8
9
10
11
From:
http://www.haskell.org/all_about_monads/html/monadfns.html

filterM :: Monad m => (a -> m Bool) -> [a] -> m [a]
filterM p []     = return []
filterM p (x:xs) = do b  <- p x
                      ys <- filterM p xs
                      return (if b then (x:ys) else ys)


My Q is in return (if b then (x:ys) else ys), ys should be type m[a], while x type is a, how can x:ys?