
3 Sep
2014
3 Sep
'14
10:05 p.m.
I wrote filterM' rather wrong. Sorry, folks. Here's a fix:
filterM' :: (Monad m) => (a -> m Bool) -> [a] -> m [a] filterM' p = go [] where go acc [] = return (reverse acc) go acc (x:xs) = do flq <- p x if flq then go (x:acc) xs else go acc xs
Or with foldr:
filterM' :: (Monad m) => (a -> m Bool) -> [a] -> m [a] filterM' p xs = foldr go (return . reverse) xs [] where go x r = \acc -> do flq <- p x if flq then r (x:acc) else r acc