Skip to content

Instantly share code, notes, and snippets.

@bucketh3ad
Last active August 29, 2015 14:00
Show Gist options
  • Save bucketh3ad/a29f4b5f36f63a54f880 to your computer and use it in GitHub Desktop.
Save bucketh3ad/a29f4b5f36f63a54f880 to your computer and use it in GitHub Desktop.
Inclusive vs. Exclusive Array Slicing
-- 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