Skip to content

filterM incompatible with haskell #87

@danr

Description

@danr

The filterM in this library has this type

filterM :: (Alternative m, Monad m) => (a -> Boolean, m a) -> m a

whereas filterM in Haskell is (reframed slighly):

filterM :: (Monad m, Traversable f) => (a -> m Boolean, f a) -> f a

The 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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions