I am studying haskell language , doing some practices. Now I am attempting to implement my own ‘index’ function , meaning it can return the index of the given element within a list, but now my version fails to run , as the following
index' n (s:x)
| s/=n = 1+index' x
| otherwise = 0
main = print(index' 3 [1,2,3,5,6,7,9])
However , if simplifying the argument into one and set the target number in the guard , as the following , it run.
index' (s:x)
| s/=3 = 1+index' x
| otherwise = 0
main = print(index' [1,2,3,5,6,7,9])
Comparing the two program , I can find what make the former fail . So I think there may be a elemental mistake in my understanding , and I need a help , please !