I have two strings; one main string, and another one of two chars (eg. "aa").
I want to see if my main string contains the second string and print its indices in the main string.
I have tried to zip the main string with itself so I can inspect every combination of the letters that comes after each other (eg. "abab" = (a,b) (b,a) (a,b)). I zip these tuples with [1..] to have the correct index where the matching string might start ((a,b) 0). Then I take fst(fst h) to extract the first letter from the tuple and see if it matches the first letter of my secondary string. If it does not find any matches, it should run again on the rest of the main string (xs). I used where to declare variable h as head(locateZip x:xs)
locate (x:xs) (y:ys) = if fst(fst h) == y && snd(fst h) == ys then snd h else locate xs (y:ys)
where h = head(locateZip x:xs)
locateZip xs = zip(zip xs(tail xs)) [0..]
snd h is used to print the index of the tuple.
It should return something like this:
locate "aabba" "aa"
0
locate "bbaab" "aa"
2
I know this might look unusual but I am still new and having trouble understanding the errors I get and what works and what doesn't.
I get an error on h saying:
Couldn't match expected type: ((Char, b2), b3) with actual type: [((b0, b0), b1)]
Is the where statement used correctly for this function?