
18 Jun
2009
18 Jun
'09
1:27 a.m.
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