From e54b15d63848461d1389b8eb143cf6af14b72ecb Mon Sep 17 00:00:00 2001 From: Don Stewart Date: Mon, 30 Apr 2007 04:48:13 +0200 Subject: shrink 'swap' darcs-hash:20070430024813-9c5c1-28d697989294c4c5ce03e44553b75a8d7bc6c03e.gz --- StackSet.hs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'StackSet.hs') 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 -- -- cgit v1.2.3