shrink 'swap'

This commit is contained in:
Don Stewart
2007-04-30 02:48:13 +00:00
parent 9fafa995c7
commit a07f0778ad

View File

@@ -202,14 +202,11 @@ promote w = maybe w id $ do
-- > swap a b . swap a b == id -- > swap a b . swap a b == id
-- --
swap :: Eq a => a -> a -> [a] -> [a] swap :: Eq a => a -> a -> [a] -> [a]
swap a b xs swap a b xs | a == b = xs -- do nothing
| a == b = xs -- do nothing | Just ai <- L.elemIndex a xs
| Just ai <- L.elemIndex a xs , Just bi <- L.elemIndex b xs = insertAt bi a (insertAt ai b xs)
, Just bi <- L.elemIndex b xs = insertAt bi a (insertAt ai b xs) where insertAt n x ys = as ++ x : tail bs
where where (as,bs) = splitAt n ys
insertAt n x ys = as ++ x : tail bs
where (as,bs) = splitAt n ys
swap _ _ xs = xs -- do nothing swap _ _ xs = xs -- do nothing
-- --