[GHC] #9385: Additions to Control.Monad

#9385: Additions to Control.Monad -------------------------------------+------------------------------------- Reporter: olf | Owner: Type: feature request | Status: new Priority: low | Milestone: Component: libraries/base | Version: 7.8.2 Keywords: | Operating System: Architecture: Unknown/Multiple | Unknown/Multiple Difficulty: Unknown | Type of failure: Blocked By: | None/Unknown Related Tickets: | Test Case: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- I'd like to propose the following additions/changes to Control.Monad: `mfilter` can be generalised: {{{#!hs gen_mfilter :: Monad m => (a -> m ()) -> m a -> m a gen_mfilter f ma = (\a -> liftM (const a) (f a)) =<< ma }}} Now we obtain the old `mfilter` as {{{#!hs gen_mfilter.(guard.) }}} Further, `m ()` is a monoid for every monad, which would cause conflicts for `[()]`, to name one example. (The usual monoid instance of `[()]` is addition of natural numbers, while the monadic monoid instance is multiplication.) More generally, the monoid `m ()` acts on every type `m a` in the following way: {{{#!hs mtimes :: Monad m => m () -> m a -> m a mtimes = gen_mfilter.const = liftM2 (flip const) when = mtimes.guard }}} For example, each element of a list can be duplicated like this: {{{#!hs mtimes [(),()] }}} To see why these functions are useful, consider the `DDist` monad of the ProbabilityMonads package: Since `DDist ()` is essentially the monoid of real numbers with multiplication, `gen_mfilter f` updates a distribution by multiplying the weight of `x` by `f x`. Another example is the state monad `ST s`, where type `(a -> ST s ())` is essentially `a -> s -> s`, so these functions encode changes that, when used with `gen_mfilter` alter state, not the value. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9385 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9385: Additions to Control.Monad -------------------------------------+------------------------------------- Reporter: olf | Owner: Type: feature | Status: new request | Milestone: Priority: low | Version: 7.8.2 Component: | Keywords: libraries/base | Architecture: Unknown/Multiple Resolution: | Difficulty: Unknown Operating System: | Blocked By: Unknown/Multiple | Related Tickets: Type of failure: | None/Unknown | Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Comment (by ekmett): This sort of proposal should go through the libraries@haskell.org mailing list rather than the GHC Trac. Please feel free to submit this for discussion there to invite wider discussion. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9385#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9385: Additions to Control.Monad -------------------------------------+------------------------------------- Reporter: olf | Owner: ekmett Type: feature | Status: infoneeded request | Milestone: Priority: low | Version: 7.8.2 Component: Core | Keywords: Libraries | Architecture: Unknown/Multiple Resolution: | Difficulty: Unknown Operating System: | Blocked By: Unknown/Multiple | Related Tickets: Type of failure: | None/Unknown | Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Changes (by thomie): * cc: core-libraries-committee@… (added) * status: new => infoneeded Comment: olf: did you submit any proposal to the libraries mailinglist for this? See also: https://www.haskell.org/haskellwiki/Library_submissions. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9385#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9385: Additions to Control.Monad -------------------------------------+------------------------------------- Reporter: olf | Owner: ekmett Type: feature request | Status: closed Priority: low | Milestone: Component: Core Libraries | Version: 7.8.2 Resolution: invalid | Keywords: report- | impact Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Changes (by thomie): * status: infoneeded => closed * resolution: => invalid Comment: Please reopen with a mandate from the libraries@ list. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9385#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC