Opened 5 years ago

Closed 5 years ago

#7435 closed feature request (wontfix)

Add swap and compose to the Prelude, or Tuple/List

Reported by: JohnWiegley Owned by:
Priority: normal Milestone:
Component: libraries/base Version: 7.6.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

    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.

Change History (3)

comment:1 Changed 5 years ago by tibbe

(This discussion is probably better to hold on the libraries@… list.)

Lets use the Data.Tuple and Data.Function modules instead of the Prelude, as the Prelude is mostly imported unqualified and we risk to break a bunch of code.

comment:2 Changed 5 years ago by guest

swap is available at Data.Tuple since GHC 7.0.1.

comment:3 Changed 5 years ago by igloo

difficulty: Unknown
Resolution: wontfix
Status: newclosed

I'm closing this ticket while the discussion is going on on the libraries list. Please reopen, or open a new ticket, if a positive decision is reached (see http://www.haskell.org/haskellwiki/Library_submissions for more details on the library submissions process).

Note: See TracTickets for help on using tickets.