Last active
August 29, 2015 14:00
-
-
Save bucketh3ad/a29f4b5f36f63a54f880 to your computer and use it in GitHub Desktop.
Inclusive vs. Exclusive Array Slicing
This file contains 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
-- subArray - Take two Ints, i and l, and an Array and returns an Array with length l starting at index i | |
subArray : Int -> Int -> Array a -> Array a | |
subArray i l = slice i (i + l - 1) | |
-- slice' - Exclusive slicing (breaks negative indices) | |
slice' i j = slice i (j-1) | |
subArray' i l = slice' i (i + l) | |
take' = slice' 0 | |
--take1 is like take, but operates on hypothetical 1-indexed arrays. | |
take1 = slice 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment