KMP algorithm (as a functor on the string type)