This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module SwapElts where | |
| -- If you have to use this function, arrays may be a better choice. | |
| swapElts i j ls = [get k x | (k, x) <- zip [0..length ls - 1] ls] | |
| where get k x | k == i = ls !! j | |
| | k == j = ls !! i | |
| | otherwise = x | |
| -- This is a nice example of how to efficiently generate test cases. | |
| -- A naive approach would have been to take separate arguments for |