-
-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
filterM incompatible with haskell #87
Comments
Thanks very much for raising this issue, @danr. :) Until recently Fantasy Land did not define a Filterable type class, so it was necessary to cobble together a filter function from the type classes available at the time. In #2 we introduced two filter functions: filter :: (Applicative f, Foldable f, Monoid (f a)) => (a -> Boolean, f a) -> f a
filterM :: (Monad m, Monoid (m a)) => (a -> Boolean, m a) -> m a The goal was to support as many filterable types as possible by providing two different derivations. The functions were necessarily given different names, with the In #37 the type of -filterM :: (Monad m, Monoid (m a)) => (a -> Boolean, m a) -> m a
+filterM :: (Alternative m, Monad m) => (a -> Boolean, m a) -> m a Recently, in #80, the two filter functions were replaced with a single unified function: filter :: Filterable f => (a -> Boolean, f a) -> f a Now that the name is available we could provide the Sanctuary equivalent of Haskell's |
The
filterM
in this library has this typewhereas
filterM
in Haskell is (reframed slighly):The important part is that the predicate returns inside the monad. This allows for example succinct implementation of powerset:
as well as enabling logging/state/etc inside the predicate:
Please consider exporting
filterM
to have the same functionality as in Haskell's Control.Monad.The text was updated successfully, but these errors were encountered: