From ba9e15e772b14280fc3dcc3a20efec9f834e9352 Mon Sep 17 00:00:00 2001 From: Spencer Janssen Date: Tue, 8 May 2007 15:09:43 +0000 Subject: [PATCH] Use 'drop 1' rather than tail, skip equality check. --- StackSet.hs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/StackSet.hs b/StackSet.hs index 74d63eb..3f615bf 100644 --- a/StackSet.hs +++ b/StackSet.hs @@ -199,10 +199,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 = head $ [insertAt bi a (insertAt ai b xs) | a /= b - ,Just ai <- [L.elemIndex a xs], Just bi <- [L.elemIndex b xs]] - ++ [xs] - where insertAt n x ys = as ++ x : tail bs +swap a b xs = maybe xs id $ do + ai <- L.elemIndex a xs + bi <- L.elemIndex b xs + return . insertAt bi a . insertAt ai b $ xs + where insertAt n x ys = as ++ x : drop 1 bs where (as,bs) = splitAt n ys --