<span style='font-family:Verdana'><span style='font-size:12px'>I don't get this example ( from Learn you a Haskell http://learnyouahaskell.com/for-a-few-monads-more ). The question is about filterM and the List Monad<br /> 
<br /> 
&gt; import Control.Monad ( filterM )<br /> 
&gt; powerset :: [a] -&gt; [[a]]&nbsp;<br /> 
&gt; powerset xs = filterM (\x -&gt; [True, False]) xs&nbsp;<br /> 
<br /> 
Looking into Control.Monad, filterM is defined:<br /> 
<br /> 
filterM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :: (Monad m) =&gt; (a -&gt; m Bool) -&gt; [a] -&gt; m [a]<br /> 
filterM _ []&nbsp;&nbsp;&nbsp;&nbsp; =&nbsp; return []<br /> 
filterM p (x:xs) =&nbsp; do<br /> 
&nbsp;&nbsp; flg &lt;- p x<br /> 
&nbsp;&nbsp; ys&nbsp; &lt;- filterM p xs<br /> 
&nbsp;&nbsp; return (if flg then x:ys else ys)<br /> 
<br /> 
Ok, let's do it step by step.<br /> 
<br /> 
&gt; test = powerset [1,2,3]<br /> 
<br /> 
'p' (in the filterM function) is<br /> 
<br /> 
p = \x -&gt; [True, False]<br /> 
<br /> 
so flg is [True, False]<br /> 
<br /> 
Let's not calculate ys for a second, but go directly to the return function.<br /> 
<br /> 
return (if [True, False] then x:ys else ys)<br /> 
<br /> 
I expect the above code to throw a "Couldn't match expected type `Bool' with actual type `[Bool]'"<br /> 
<br /> 
So I can't see how the trick works! Any hint?<br /> 
</span></span>