summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeil Mitchell http://www.cs.york.ac.uk/~ndm/ <none>2007-05-08 14:31:58 +0200
committerNeil Mitchell http://www.cs.york.ac.uk/~ndm/ <none>2007-05-08 14:31:58 +0200
commit1f57620df2ff18881007b3bc56fb8ffbe5efbccf (patch)
tree03c72c3d99fbdb224549725d5b3214dcb18534d5
parentac7b08a67c5864795ee98c37bbe8f54de5ffce06 (diff)
downloadmetatile-1f57620df2ff18881007b3bc56fb8ffbe5efbccf.tar
metatile-1f57620df2ff18881007b3bc56fb8ffbe5efbccf.zip
Change the swap function so its Haskell 98, by using list-comps instead of pattern-guards.
darcs-hash:20070508123158-fbc8d-1592375172ef513d85c5e0095c689abf9ac5fc9b
-rw-r--r--StackSet.hs11
1 files 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: