You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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 M suffix hinting at the Monad m constraint. Although the M suffix may have been added for the same reason as in Haskell, Sanctuary's filterM was never intended to mirror its Haskell namesake.
In #37 the type of filterM was changed to permit Z.filterM(odd, Just(4)):
-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::Filterablef=> (a->Boolean, fa) ->fa
Now that the name is available we could provide the Sanctuary equivalent of Haskell's filterM. I find your powerset example extremely compelling! If you're interested in working on a pull request for this addition, please say so. :)
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: