-
-
Notifications
You must be signed in to change notification settings - Fork 20
Open
Description
The filterM in this library has this type
filterM :: (Alternative m, Monad m) => (a -> Boolean, m a) -> m awhereas filterM in Haskell is (reframed slighly):
filterM :: (Monad m, Traversable f) => (a -> m Boolean, f a) -> f aThe important part is that the predicate returns inside the monad. This allows for example succinct implementation of powerset:
powerset :: [a] -> [[a]]
powerset = filterM (const [False, True])as well as enabling logging/state/etc inside the predicate:
countingFilterM :: (a -> Bool) -> [a] -> State Int [a]
countingFilterM p = filterM (\ x -> modify succ >> return (p x))Please consider exporting filterM to have the same functionality as in Haskell's Control.Monad.
Metadata
Metadata
Assignees
Labels
No labels