I found this piece of code on a question which is similar to one which I am trying to solve and I'm trying to apply the logic of this function to my problem. However, the explanation of the code isn't completely clear on the question. The code is as follows:
splitAtIndex :: Int -> [a] -> ([a], [a])
splitAtIndex 0 xs = ([], xs)
splitAtIndex _ [] = ([], [])
splitAtIndex x (y:ys) = (y:ys', ys'')
where
(ys', ys'') = splitAtIndex (x - 1) ys
The way I understand this, is that you take the index and the whole list and form a tuple of lists where the tuple of lists is equal to the recursive call of index-1 of the tail of the list. Am I missing something here? Is the use of apostrophes important here? I really don't see where the split of the list takes place. I'm sure once explained it will seem simple but I can't seem to grasp it.
Thanks!
ys'is a regular identifier. It could be any other identifier . Usexyzzy123or whatever instead. It is not so clear what your other difficulties are. "Where" the split takes place? This entire function is "where". The new lists are built gradually. If you expect the original list to be destructively split at some place, then no, this does not happen in Haskell.