roogaal wrote on February 28th, 2007 at 07:06 pm  avva and I
were puzzling over it too; here's how we figured it out.  First,
in terms of types, yes, it agrees: filtermM :: Monad m => (a ->
m Bool) -> [a] -> m [a] -- or, concretized with [] for m:
filtermM ::         => (a -> [Bool]) -> [a] -> [[a]] (const
[True, False]) sure has type (a -> [Bool]), so the currying
filterM with it certainly does agree with the type of powerset.
But why does it agree with the meaning?  Here's the source of
filterM, from GHC (it's in the source for Control.Monad):
filterM _ []     =  return [] filterM p (x:xs) =  do    flg <- p
x    ys  <- filterM p xs    return (if flg then x:ys else ys) So
what's up with (const [True, False]) ? This means a constant
function returning [True, False]; same as a \_ -> [True, False].
The first line where flg is mentioned, that simply throws away
the x and forces the constant function for a value, and so
reduces to:     flg <- [True, False] Before grokking the monadic
stuff, this looks very weird