[GHC] #7435: Add swap and compose to the Prelude, or Tuple/List

GHC cvs-ghc at haskell.org
Tue Nov 20 19:56:10 CET 2012


#7435: Add swap and compose to the Prelude, or Tuple/List
-----------------------------+----------------------------------------------
Reporter:  JohnWiegley       |          Owner:                  
    Type:  feature request   |         Status:  new             
Priority:  normal            |      Component:  libraries/base  
 Version:  7.6.1             |       Keywords:                  
      Os:  Unknown/Multiple  |   Architecture:  Unknown/Multiple
 Failure:  None/Unknown      |      Blockedby:                  
Blocking:                    |        Related:                  
-----------------------------+----------------------------------------------
 {{{
     swap :: (a,b) -> (b,a)
     swap = snd &&& fst
 }}}
 Fairly obvious, but strangely missing.
 {{{
     compose :: [(a -> a)] -> a -> a
     compose = foldr (.) id

     composeM :: [(a -> m a)] -> a -> m a
     composeM = foldr (<=<) return
 }}}
 This can be done with Endo, of course, but the result is awkward.  The
 idiom
 of composing a list of endomorphisms occurs often enough that you can
 Google
 for it.

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/7435>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler



More information about the Glasgow-haskell-bugs mailing list