I want to define my own infix operator using Haskell that concats two strings together. However, I want to throw in an extra clause where the operator will concat over the overlapping elements in both strings. So an example would be
"eagle" myinfix "eagleeyes" = "eagleeyes"
"water" myinfix "book" = "waterbook"
"need" myinfix "education" = "needucation"
I already figured out how to return the overlapping portions in the strings with:
check x y = head $ filter (`isPrefixOf` y) (tails x)
But I don’t know how to incorporate that in. Any help?
You’re going about it in slightly the wrong way.
That is, you don’t really care what the overlap is, you just care whether you have reached it.
Here’s another solution without the explicit recursion.
Here we go about finding the overlap, as in your
check, but instead of keeping the overlap, we yield the portion ofxsthat doesn’t overlap.