Created
December 28, 2013 06:04
-
-
Save nfunato/8156534 to your computer and use it in GitHub Desktop.
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
| -- O(n) revTake and revDrop using list-numeral alike Church-numeral | |
| -- (from Richard O'Keefe's post to haskell-cafe, i.e. | |
| -- http://www.haskell.org/pipermail/haskell-cafe/2010-September/083905.html) | |
| -- | l | | |
| -- +----------------+-----+ | |
| -- | l-n (_:m) n | | |
| revTake n xs = drop' (drop n xs) xs | |
| where drop' (_:m) (_:xs) = drop' m xs | |
| drop' _ xs = xs | |
| revDrop n xs = take' (drop n xs) xs | |
| where take' (_:m) (x:xs) = x : take' m xs | |
| take' _ _ = [] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment