I am a beginner in Haskell programming and have gotten an assignment to create a function that checks if a given string is the substring of another string and if it is it returns the position of the substring in the main string. This is what I have so far:
findString :: String -> String -> Integer
findString mainstring substring
| length substring > length mainstring = (-1)
| take (length substring) mainstring == substring = 0
| otherwise = 1 + findString (drop 1 mainstring) substring
The instructions for this assignment explicitly state that I have to use findString :: String -> String -> Integer and that if the substring is not a substring of the mainstring it should return (-1). Right now the recursive part of the function interferes with the result of| length substring > length mainstring = (-1) by adding +1 to it for each recursion but I just want a static (-1). I feel like I'm very close here but I've been stuck on this one for quite some time now. Any help would be appreciated!