Skip to content

Instantly share code, notes, and snippets.

@jutememo
Created April 25, 2011 01:51
Show Gist options
  • Save jutememo/940063 to your computer and use it in GitHub Desktop.
Save jutememo/940063 to your computer and use it in GitHub Desktop.
swap i j xs = let a = slice' 0 (i-1)
b = slice' (i+1) (j-1)
c = slice' (j+1) (length xs - 1)
in a ++ (xs!!j):b ++ (xs!!i):c
where
slice' i j = slice i j xs
slice i j = snd . splitAt i . fst . splitAt (j+1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment