[GHC] #8587: Add operator <%>, or similar, as <%> = flip fmap

#8587: Add operator <%>, or similar, as <%> = flip fmap -------------------------------------------+------------------------------- Reporter: bunimo | Owner: Type: feature request | Status: new Priority: normal | Milestone: _|_ Component: Prelude | Version: 7.6.3 Keywords: | Operating System: Architecture: Unknown/Multiple | Unknown/Multiple Difficulty: Easy (less than 1 hour) | Type of failure: Blocked By: | None/Unknown Related Tickets: | Test Case: | Blocking: -------------------------------------------+------------------------------- Often, piping results through one function after another provides a good conceptual flow to the code. But when the functions are a mixture of monadic and pure, it can seem more convoluted than it actually is. For example, compare: {{{ do a <- monadicResult let b = pureFunction2 . pureFunction 1 <$> a c <- monadicFunction1 b >>= monadicFunction2 }}} to {{{ c <- monadicFunction2 =<< monadicFunction1 =<< pureFunction2 <$> pureFunction1 <$> monadicResult }}} But this reading from bottom-to-up seems backwards, especially considering monadic code is more traditionally top-to-bottom, left-to-right. I'd like to propose adding a new operator {{{ infixl 1 <%> (<%>) :: Functor f => f a -> (a -> b) -> f b (<%>) = flip fmap }}} so that the following can be written. It is obvious what the intent of the code is. There are no unnecessary temporary variables. It conforms to typical monadic code direction. It is visually pleasing. {{{ c <- monadicResult <%> pureFunction1 <%> pureFunction2 >>= monadicFunction1 >>= monadicFunction2 }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8587 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8587: Add operator <%>, or similar, as <%> = flip fmap -------------------------------+------------------------------------------- Reporter: bunimo | Owner: Type: feature | Status: closed request | Milestone: _|_ Priority: normal | Version: 7.6.3 Component: Prelude | Keywords: Resolution: invalid | Architecture: Unknown/Multiple Operating System: | Difficulty: Easy (less than 1 hour) Unknown/Multiple | Blocked By: Type of failure: | Related Tickets: None/Unknown | Test Case: | Blocking: | -------------------------------+------------------------------------------- Changes (by monoidal): * status: new => closed * resolution: => invalid Comment: Proposals to add new functions or instances should be discussed on the [http://www.haskell.org/mailman/listinfo/libraries libraries mailing list] first. Once you get approval, you can paste a link to the discussion here. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8587#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC