Skip to content

Instantly share code, notes, and snippets.

@jutememo
Created April 25, 2011 02:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jutememo/940084 to your computer and use it in GitHub Desktop.
Save jutememo/940084 to your computer and use it in GitHub Desktop.
swap i j xs0 = swap' [] withIdx
where
withIdx = zip [0..] xs0
swap' acc [] = reverse acc
swap' acc ((idx,x1):xs1) | idx == i = swap' ((xs0!!j):acc) xs1
| idx == j = swap' ((xs0!!i):acc) xs1
| otherwise = swap' (x1:acc) xs1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment