Adding swap to Data.Tuple

Edward Kmett ekmett at gmail.com
Thu Jun 18 01:44:58 EDT 2009


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 <jonathanccast at fastmail.fm>wrote:

> 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
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/libraries/attachments/20090618/6f9c4947/attachment.html


More information about the Libraries mailing list