I could not figure out in my code what function is raising (*** Exception: Prelude.!!: negative index
since this exception is not very descriptive about the error. Is there any way to detect exactly what custom function is calling !!
and raising this error.
This is a simple reproducible example of the error when is called index_around 0 [1, 2, 3]
, here the exception text doesn't describe if the exception is raised by index_before
or by index_after
function.
index_before :: Int -> [a] -> a
index_before i list = list !! (i - 1)
index_after :: Int -> [a] -> a
index_after i list = list !! (i + 1)
index_around :: Int -> [a] -> (a, a)
index_around i list = (index_before i list, index_after i list)