I'm trying to get the the index of an element that is in a list.
However the problem I am having is when the element isn't in the list.
I'm thinking that maybe tail recursion is in order, but I'm not really sure how to go about it.
whatIndex sought [] = -1
whatIndex sought (a:xs) =
if sought == a
then 0
else 1 + whatIndex sought xs
Edit:
When it's not in the list, it should return -1
Example:
whatIndex 3 [1,2,3] == 2
whatIndex 3 [0,1,2] == -1
Edit: Was able to get it to work.
go)?