Adding swap to Data.Tuple

Jonathan Cast jonathanccast at fastmail.fm
Thu Jun 18 01:27:08 EDT 2009


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




More information about the Libraries mailing list