Skip to content

Instantly share code, notes, and snippets.

@jutememo
Created April 25, 2011 02:52
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/940091 to your computer and use it in GitHub Desktop.
Save jutememo/940091 to your computer and use it in GitHub Desktop.
swap i j xs0 = swap' 0 xs0
where
swap' idx [] = []
swap' idx (x1:xs1) | idx == i = xs0 !! j : swap''
| idx == j = xs0 !! i : swap''
| otherwise = x1 : swap''
where
swap'' = swap' (idx+1) xs1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment