Ticket #3298 (closed proposal: fixed)

Opened 4 years ago

Last modified 3 years ago

Add swap to Data.Tuple

Reported by: r6 Owned by:
Priority: normal Milestone: Not GHC
Component: libraries/base Version: 6.10.2
Keywords: Cc: merehap
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

I think swap is a widely accepted name for the function. There is only the question of strictness. I suggest swap for the lazy version and swap' for the strict version

swap ~(a,b) = (b,a)

swap' (a,b) = (b,a)

Change History

follow-ups: ↓ 3 ↓ 4   Changed 4 years ago by YitzGale

I would usually spell this

swap = uncurry $ flip (,)

That supports your choice of the lazy version as unprimed.

  Changed 4 years ago by MartijnVanSteenbergen

Whichever version is chosen, I think it should be reexported as part of the Prelude, too.

in reply to: ↑ 1   Changed 4 years ago by YitzGale

I wrote:

That supports your choice of the lazy version as unprimed.

I now retract that comment, based on discussion in the thread on haskell-cafe:

 http://www.haskell.org/pipermail/haskell-cafe/2009-June/062772.html

I now support the addition of only the strict version:

swap (a, b) = (b, a)

in reply to: ↑ 1   Changed 4 years ago by simonmar

  • difficulty set to Unknown

Replying to YitzGale:

I would usually spell this {{{ swap = uncurry $ flip (,) }}} That supports your choice of the lazy version as unprimed.

I had tongue firmly in cheek when I suggested using this definition on haskell-cafe a while ago. I am not sure whether to be horrified or amused that some people would actually prefer to write it that way!

  Changed 4 years ago by MartijnVanSteenbergen

Maybe a bit of both? :-)

  Changed 4 years ago by YitzGale

I wrote:

swap = uncurry $ flip (,)

simonmar wrote:

I had tongue firmly in cheek when I suggested using this definition on haskell-cafe a while ago. I am not sure whether to be horrified or amused that some people would actually prefer to write it that way!

He he, I didn't even remember that, perhaps I didn't see it.

Anyway, I never meant to suggest that it should actually be written that way in the libraries. Just that the laziness of the natural points-free version is evidence in support of laziness. And I have retracted even that claim.

  Changed 4 years ago by igloo

  • milestone set to Not GHC

  Changed 3 years ago by merehap

  • cc merehap added
  • failure set to None/Unknown

  Changed 3 years ago by igloo

  • status changed from new to closed
  • resolution set to wontfix

Looks like an abandoned proposal

  Changed 3 years ago by simonmar

  • status changed from closed to new
  • resolution wontfix deleted

  Changed 3 years ago by simonmar

  • status changed from new to closed
  • resolution set to fixed

Done:

Tue May  4 10:53:39 BST 2010  Simon Marlow <marlowsd@gmail.com>
  * Add swap (#3298)
Note: See TracTickets for help on using tickets.