From a07f0778add6d27fd1e89ca33dcc5b8a65a4ec41 Mon Sep 17 00:00:00 2001 From: Don Stewart Date: Mon, 30 Apr 2007 02:48:13 +0000 Subject: [PATCH] shrink 'swap' --- StackSet.hs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/StackSet.hs b/StackSet.hs index 73c3bfb..a480792 100644 --- a/StackSet.hs +++ b/StackSet.hs @@ -202,14 +202,11 @@ promote w = maybe w id $ do -- > swap a b . swap a b == id -- swap :: Eq a => a -> a -> [a] -> [a] -swap a b xs - | a == b = xs -- do nothing - | Just ai <- L.elemIndex a xs - , Just bi <- L.elemIndex b xs = insertAt bi a (insertAt ai b xs) - where - insertAt n x ys = as ++ x : tail bs - where (as,bs) = splitAt n ys - +swap a b xs | a == b = xs -- do nothing + | Just ai <- L.elemIndex a xs + , Just bi <- L.elemIndex b xs = insertAt bi a (insertAt ai b xs) + where insertAt n x ys = as ++ x : tail bs + where (as,bs) = splitAt n ys swap _ _ xs = xs -- do nothing --