<div dir="ltr">From base-4.6.0.1 [1] the filterM is implemented like this:<div><br></div><div><div>filterM          :: (Monad m) => (a -> m Bool) -> [a] -> m [a]</div><div>filterM _ []     =  return []</div><div>filterM p (x:xs) =  do</div><div>   flg <- p x</div><div>   ys  <- filterM p xs</div><div>   return (if flg then x:ys else ys)</div></div><div><br></div><div>So</div><div>filterM (\x -> [True, False]) [1,2] is</div><div><br></div><div>filterM (\x -> [True, False]) (1:[2])</div><div>do</div><div>    flg <- (\x -> [True, False]) 1<br>    ys <- filterM (\x -> [True, False]) [2]<br>    return (if flg then x:ys else ys)</div><div><br></div><div>do</div><div>    flg <- [True, False]</div><div>    ys <- [[2], []]</div><div>    return (if flg then 1:ys else ys)</div><div><br></div><div>You get the idea. You'll end up with [[1,2],[1],[2],[]]</div><div><br></div><div>Hope this helps,</div><div>Alexey Shmalko</div><div><br></div><div>[1] <a href="https://hackage.haskell.org/package/base-4.6.0.1/docs/src/Control-Monad.html">https://hackage.haskell.org/package/base-4.6.0.1/docs/src/Control-Monad.html</a></div></div>