I have a function that has parameters
whatIndex :: (Eq a) => a -> [a] -> Integer
where I return the index of a inside [a], starting at 0, or return -1 if it's not found. This is what I wrote
module WhatIndex where
whatIndex :: (Eq a) => a -> [a] -> Integer
whatIndex p [] = -1
whatIndex p (a:as)
| p==a = index
| otherwise = whatIndex p as
where index = 1+whatIndex p as
Obviously, I'm not correctly increasing index here. Any idea why this isn't working? Also, I cannot change parameters.
========================
Here is some basic input/output
whatIndex 3 [] = -1
whatIndex 2 [1,2,3,2,1]=1
whatIndex 1 [1,2,3,2,1]=0
whatIndex 'b' ['a' .. 'z']=1
Maybe Int, because you want to make it clear in the type that the function is partial. Such a function,elemIndex, already exists inData.List--you can take a look at the source here.