Skip to content

Instantly share code, notes, and snippets.

@jutememo
Created April 25, 2011 04:18
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/940153 to your computer and use it in GitHub Desktop.
Save jutememo/940153 to your computer and use it in GitHub Desktop.
swap 0 j (x:xs) = idxAt (j-1) xs : set x (j-1) xs
where
idxAt 0 (x:_) = x
idxAt j (_:xs) = idxAt (j-1) xs
set x 0 (_:ys) = x:ys
set x j (y:ys) = y:set x (j-1) ys
swap i j (x:xs) = x : swap (i-1) (j-1) xs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment