Created
November 7, 2013 03:26
-
-
Save mmitou/7348481 to your computer and use it in GitHub Desktop.
継続渡し的なsplit
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
| replace :: Int -> Int -> [a] -> [a] | |
| replace i j xs | 0 <= i && i < j && j < length xs = mkHead . (:) xj . mkBody . (:) xi $ tail | |
| | null xs = [] | |
| | otherwise = xs | |
| where | |
| (mkHead, (xi:bodyTail)) = splitCps i xs id | |
| (mkBody, (xj:tail)) = splitCps (j - i - 1) bodyTail id | |
| splitCps :: Int -> [a] -> ([a] -> [a]) -> ([a] -> [a], [a]) | |
| splitCps 0 xs f = (f, xs) | |
| splitCps _ [] f = (f, []) | |
| splitCps n (x:xs) f = splitCps (n - 1) xs (\ys -> f (x:ys)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment