on February 28th, 2007 at 09:11 pm |
You could implement filterM in reverse, I guess:
I wonder if you can implement filterM as a combination of smaller functions? (Like how mapM is sequence . map f.)
rfilterM :: Monad m => (a -> m Bool) -> [a] -> m [a]
rfilterM f [] = return []
rfilterM f (x:xs) = do mxs <- rfilterM f xs; pred <- f x
if pred then return (x:mxs)
else return mxs
powerset' = rfilterM (const [True,False])
main = do
print $ powerset' [1,2,3]I wonder if you can implement filterM as a combination of smaller functions? (Like how mapM is sequence . map f.)
(Read Comments)