
Good point. This brings us back to Russell's original suggestion of swap and
swap' to cover both cases. That module has all of ~4 methods in it right
now. -- I'm evaluating that lazily -- so its not exactly like adding both
will break the complexity budget of a self-contained module designed to deal
with tuples. ;)
-Edward Kmett
On Thu, Jun 18, 2009 at 1:27 AM, Jonathan Cast
On Thu, 2009-06-18 at 01:24 -0400, Edward Kmett wrote:
If we look at swap from the standpoint of the laws/RULES it should support, viewing Hask over (,) as a symmetric monoidal category you get something like:
{-# RULES "swap . swap = id" forall x. swap (swap x) = x "fst . swap = snd" forall x. fst (swap x) = snd x "snd . swap = fst" forall x. snd (swap x) = fst x #-}
That seems to argue for the lazy definition being the default to avoid the strict pattern match in swap breaking the latter very pleasing equalities.
Lazy swap fails the swap . swap rule:
swap (swap undefined) = swap (snd undefined, fst undefined) = swap (undefined, undefined) = (undefined, undefined)
which is distinct from undefined because Haskell tuples are lifted.
jcc