Talk:99 questions/Solutions/18

From HaskellWiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Hi. I'm wondering if this solution still works in the current Haskell version.

slice xs (i+1) k = snd (split (fst (split xs k)) i)


The solution:

slice xs i k | i>0 = take (k-i+1) $ drop (i-1) xs

will not give proper results for negative indices particularly when the first index is negative and the second one within the length of the list.