From 1f57620df2ff18881007b3bc56fb8ffbe5efbccf Mon Sep 17 00:00:00 2001 From: "Neil Mitchell http://www.cs.york.ac.uk/~ndm/" Date: Tue, 8 May 2007 14:31:58 +0200 Subject: Change the swap function so its Haskell 98, by using list-comps instead of pattern-guards. darcs-hash:20070508123158-fbc8d-1592375172ef513d85c5e0095c689abf9ac5fc9b --- StackSet.hs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/StackSet.hs b/StackSet.hs index 3e35f53..7883daa 100644 --- a/StackSet.hs +++ b/StackSet.hs @@ -1,5 +1,3 @@ -{-# OPTIONS -fglasgow-exts #-} - ----------------------------------------------------------------------------- -- | -- Module : StackSet @@ -8,7 +6,7 @@ -- -- Maintainer : dons@cse.unsw.edu.au -- Stability : stable --- Portability : portable, needs GHC 6.6 +-- Portability : portable -- ----------------------------------------------------------------------------- -- @@ -201,12 +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 | a == b = xs -- do nothing - | Just ai <- L.elemIndex a xs - , Just bi <- L.elemIndex b xs = insertAt bi a (insertAt ai b xs) +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 where (as,bs) = splitAt n ys -swap _ _ xs = xs -- do nothing -- -- cycling: -- cgit v1.2.3